Use PHP to construct nested arrays. if you want to construct a nested array online, you can output JSON for foreground page cascading menus. However, this cannot be implemented at all times. The general structure is as follows: product [commod] & nbsp; |-beverage type [drink] (clsID, clsName) & nbsp; | & nbsp; & nested arrays using PHP architecture, online and so on
I want to construct a nested array to output JSON for the foreground page cascading menu, but it cannot be implemented at all times.
The general structure is as follows:
Product [commod]
|-Beverage [drink] (clsID, clsName)
|-Carbonated drinks [sodas] (itemID, itemName)
|-Fruit juice beverage [juice] (itemID, itemName)
|
|-Food [food] (clsID, clsName)
|-Fresh [fresh] (itemID, itemName)
|-Cooked (itemID, itemName)
I wrote one but it didn't work.
/**/
$ Tmparr [] = array ('clsid' => '01', 'clsname' => 'beverage class ');
Array_push ($ tmparr [0], array ('itemid' => '123', 'itemname' => 'Carbonated beverage ', 'itemrate' => '123 '));
Array_push ($ tmparr [0], array ('itemid' => '000000', 'itemname' => 'juiced beverage ', 'itemrate' => '2016 '));
$ Tmparr [] = array ('clsid '=> '02', 'clsname' => 'food food ');
$ Tmp [] = array ('itemid' => '123', 'itemname' => 'aliyun', 'itemrate' => '3% ');
$ Tmp [] = array ('itemid' => '123', 'itemname' => 'cookier', 'itemrate' => '3% ');
Array_push ($ tmparr [1], $ tmp );
$ Json_str = json_encode ($ tmparr );
// Print_r ($ tmparr );
Echo $ json_str;
?>
Architecture JSON
------ Solution --------------------
You can write it directly.
$ Tmparr ['drink '] = array ('clsid' => '01', 'clsname' => 'beverage class'); // [drink]
$ Tmparr ['drink '] ['sodas'] = array ('itemid' => '123456', 'itemname' => 'Carbonated beverage ', 'itemrate' => '123'); // [sodas]
$ Tmparr ['drink '] ['juice'] = array ('itemid' => '123456', 'itemname' => 'juice beverage ', 'itemrate' => '123'); // [juice]
$ Tmparr ['food'] = array ('clsid '=> '02', 'clsname' => 'food'); // [food]
$ Tmparr ['food'] ['fresh'] = array ('itemid' => '123', 'itemname' => 'Shanghai ', 'itemrate' => '3% '); // [fresh]
$ Tmparr ['food'] ['cooked'] = array ('itemid' => '123', 'itemname' => 'cooking ', 'itemrate' => '3% '); // [cooked]