array-push

Can I use array_push on a SESSION array in php?

妖精的绣舞 提交于 2019-11-27 01:46:10
I have an array that I want on multiple pages, so I made it a SESSION array. I want to add a series of names and then on another page, I want to be able to use a foreach loop to echo out all the names in that array. This is the session: $_SESSION['names'] I want to add a series of names to that array using array_push like this: array_push($_SESSION['names'],$name); I am getting this error: array_push() [function.array-push]: First argument should be an array Can I use array_push to put multiple values into that array? Or perhaps there is a better, more efficient way of doing what I am trying

PHP add elements to multidimensional array with array_push

北战南征 提交于 2019-11-26 12:08:35
问题 I have a multidimensional array $md_array and I want to add more elements to the sub-arrays recipe_type and cuisine coming from a loop that reads data from a table. In the loop, I create a new table $newdata for each row: $newdata = array ( \'wpseo_title\' => \'test\', \'wpseo_desc\' => \'test\', \'wpseo_metakey\' => \'test\' ); and then, using array_push() I need to append the $newdata arrays to the following multidimensional array: $md_array= array ( \'recipe_type\' => array ( 18 => array (