php


Convert an incoming ajax array to a multi dimensional php array


I have an php array like this
Array ( [ord['ord1'][0]] => shirt [ord['ord2'][0]] => pant)
I would like to make it like the below
Array ( [ord] => Array ( [ord1] => Array ( [0] => shirt ) [ord2] => Array ( [0] => pant ) ) )
Please let me know how I can i achieve this when you get a chance.
You key string is ord['ord1'][0], you have to parse it.
check the Live demo
<?php
$array = json_decode( '{"ord[\'ord1\'][0]":"shirt","ord[\'ord2\'][0]":"pant"}', true);
$result = [];
foreach($array as $k => $v)
{
$keys = explode("'", str_replace(['[', ']'], '', $k));
$arr = [];
$ref = &$arr;
while($key = current($keys))
{
$ref = &$ref[$key];
next($keys);
}
$ref[] = $v;
$result[] = $arr;
}
print_r($result);

Related Links

How to remove previous method at URL codeigniter?
Update database with PHP
Delete all lines before a line that included specific word in a file by using php
jquery datepicker disable specific days and dates dynamically
Different formats of JSON responses on different servers
Changing up a score calculating script
Preg_Match PHP Script not working
wordpress - unable to checkboxes values DB
Laravel mail not sending
Access to config in static method
Block ajax script execution before the previous call succeeded
CakePHP 3.0:attempt to create Multilanguage Site
Does redirecting www to https:// require AllowOverride or can it be set globally?
How to declare an abstract variadic function in PHP before version 5.6?
using autocomplete value to get new value from sqlite and populate edittext
Edit formatting parameters passed by the URL CakePHP 3

Categories

HOME
automapper
opencart
tomcat
apple-push-notifications
shinyapps
yii
selenium-builder
devexpress
mousemove
autocomplete
tibco
clone
port
reportviewer
nsstring
smartgwt
stimulsoft
pushdown-automaton
global-variables
vmware-workstation
bluemix-mobile-services
node-webkit
dashdb
multi-dimensional-scaling
android-cardview
tsung
nic
google-play-developer-api
tightvnc
vcenter
python-2.x
cucumber-junit
xmlunit
db2-luw
grails-2.5
nppexec
spinner
cordys-opentext
jslint
django-crispy-forms
gitolite
game-center
word-cloud
jqgrid-asp.net
transparency
react-intl
rightnow-crm
viewmodel
sonarqube5.2
rm
ol3-google-maps
knockout-2.0
beeline
nusoap
phppgadmin
redisson
scala-collections
mathjs
seccomp
traversable
android-syncadapter
jemdoc
distributed-cache
gulp-uglify
as3-api
voronoi
webgrind
diawi
srv-record
screen-orientation
supersocket.net
uitest
alwayson
componentart
tree-structure
python-c-extension
baseadapter
directorysearcher
phonegap-facebook-plugin
sunos
encryption-symmetric
rubber
window-resize
git-reset
sql-function
xulrunner
jack
application-blocks
stty
idispatch
onconfigurationchanged
stretch
audiotoolbox
pageheap
struts2-s2hibernate
wcf-callbacks
zend-server-ce
dynamic-c
litespeed
getopts
botnet
office-automation
sql-parametrized-query
simile
printqueue
solandra
android-2.1-eclair
icicles
j2mepolish
raw-data
aspbutton
3270
inversion
downcasting
database-cloning
efs

Resources

Encrypt Message