php - Dynamically creating multidimensional arrays to be encoded into JSON -


i have section of array defined:

$arrdata['categories'] = array(); array_push($arrdata['categories'],array("category" => array(array("label"=>"beef"),array("label"=>"chicken")))); array_push($arrdata['categories'][0]['category'],array("label"=>"pork")); 

the arrays nested encodes json {[{[{[]}]}]} formatted properly.

however, need create these types of meats dynamically, not statically. when try add onto array in third line of code simulate dynamic creation, throws error:

warning: array_push() expects parameter 1 array, null given

well, $arrdata['categories'][0]['category] array, why shoot me down?

to show myself i'm not crazy, var_dump $arrdata['categories'][0]['category'] , array of size 1:

array (size=1) 'category' =>  array (size=2)    0 =>       array (size=1)        'label' => string 'beef' (length=4)    1 =>       array (size=1)        'label' => string 'chicken' (length=7) 

its capitalization. in third line variable $arrdata capitalized differently others ($arrdata)


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -