voci mon problème : je souhaite insérer dans bdd mysql des données en json
Etape 1/
Mon résultat Json
[{"title":"Account","customSelect":"1","select2ScrollPosition":{"x":0,"y":0},"id":1,"__domenu_params":{}},{"title":"Settings","customSelect":"3","select2ScrollPosition":{"x":0,"y":0},"id":2,"__domenu_params":{},"children":[{"title":"Call","customSelect":"4","id":3,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0},"children":[{"title":"Support","customSelect":"3","id":4,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0}},{"title":"Email","customSelect":"4","id":5,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0}}]}]},{"title":"TOTO","customSelect":"3","id":6,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0}},{"title":"Orders","customSelect":"select something...","id":7,"__domenu_params":{}},{"title":"Manage","customSelect":"select something...","id":8,"__domenu_params":{}},{"title":"tata","customSelect":"1","id":9,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0}}]
Etape 2: Ensuite avec : $php_arr = json_decode($json,true);
echo "<pre>";
print_r($php_arr);
echo "</pre>";
j'obtient ceci :
Array
(
[0] => stdClass Object
(
=> Account
[customSelect] => 1
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
=> 1
[__domenu_params] => stdClass Object
(
)
)
[1] => stdClass Object
(
=> Settings
[customSelect] => 3
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
=> 2
[__domenu_params] => stdClass Object
(
)
=> Array
(
[0] => stdClass Object
(
=> Call
[customSelect] => 4
=> 3
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
=> Array
(
[0] => stdClass Object
(
=> Support
[customSelect] => 3
=> 4
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
)
[1] => stdClass Object
(
=> Email
[customSelect] => 4
=> 5
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
)
)
)
)
)
[2] => stdClass Object
(
=> TOTO
[customSelect] => 3
=> 6
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
)
[3] => stdClass Object
(
=> Orders
[customSelect] => select something...
=> 7
[__domenu_params] => stdClass Object
(
)
)
[4] => stdClass Object
(
=> Manage
[customSelect] => select something...
=> 8
[__domenu_params] => stdClass Object
(
)
)
[5] => stdClass Object
(
=> tata
[customSelect] => 1
=> 9
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
)
)
il réaliser ce menu de la forme :
Account
.riton
Orders
.Email
.Support
.nouveau
Manage
.Settings
Settings
.TOTO
.Call
tonton
il faut une fonction récursive, mais je sais pas la faire... merci de votre aide!!!!
Etape 1/
Mon résultat Json
[{"title":"Account","customSelect":"1","select2ScrollPosition":{"x":0,"y":0},"id":1,"__domenu_params":{}},{"title":"Settings","customSelect":"3","select2ScrollPosition":{"x":0,"y":0},"id":2,"__domenu_params":{},"children":[{"title":"Call","customSelect":"4","id":3,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0},"children":[{"title":"Support","customSelect":"3","id":4,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0}},{"title":"Email","customSelect":"4","id":5,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0}}]}]},{"title":"TOTO","customSelect":"3","id":6,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0}},{"title":"Orders","customSelect":"select something...","id":7,"__domenu_params":{}},{"title":"Manage","customSelect":"select something...","id":8,"__domenu_params":{}},{"title":"tata","customSelect":"1","id":9,"__domenu_params":{},"select2ScrollPosition":{"x":0,"y":0}}]
Etape 2: Ensuite avec : $php_arr = json_decode($json,true);
echo "<pre>";
print_r($php_arr);
echo "</pre>";
j'obtient ceci :
Array
(
[0] => stdClass Object
(
=> Account
[customSelect] => 1
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
=> 1
[__domenu_params] => stdClass Object
(
)
)
[1] => stdClass Object
(
=> Settings
[customSelect] => 3
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
=> 2
[__domenu_params] => stdClass Object
(
)
=> Array
(
[0] => stdClass Object
(
=> Call
[customSelect] => 4
=> 3
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
=> Array
(
[0] => stdClass Object
(
=> Support
[customSelect] => 3
=> 4
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
)
[1] => stdClass Object
(
[customSelect] => 4
=> 5
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
)
)
)
)
)
[2] => stdClass Object
(
=> TOTO
[customSelect] => 3
=> 6
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
)
[3] => stdClass Object
(
=> Orders
[customSelect] => select something...
=> 7
[__domenu_params] => stdClass Object
(
)
)
[4] => stdClass Object
(
=> Manage
[customSelect] => select something...
=> 8
[__domenu_params] => stdClass Object
(
)
)
[5] => stdClass Object
(
=> tata
[customSelect] => 1
=> 9
[__domenu_params] => stdClass Object
(
)
[select2ScrollPosition] => stdClass Object
(
[x] => 0
[y] => 0
)
)
)
il réaliser ce menu de la forme :
Account
.riton
Orders
.Support
.nouveau
Manage
.Settings
Settings
.TOTO
.Call
tonton
il faut une fonction récursive, mais je sais pas la faire... merci de votre aide!!!!