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
Post a Comment