So, here I go with my tasty code...
//array holds cake name and price
$cakes = array('cherry' => 3.49 , 'cinnamon' => 1.49); //tasty, ha?
$new_cakes = array('chocolate' => 1.99 ,
'cheese' => 3.99,
'vanilla' => 2.49); //yup, new cakes, freshly baked...
array_push($cakes, $new_cakes); //pushing cakes? watch out not to melt the chocolate
Now, printing this array would produce:
Array
(
[cherry] => 3.49
[cinnamon] => 1.49
[0] => Array
(
[chocolate] => 1.99
[cheese] => 3.99
[vanilla] => 2.49
)
)
Of course, that is not what I want. I need all my cakes in one basket... The problem is of course that I am pushing the $new_cakes array itself onto the first array, instead of pushing the elements in the array.
So, in an effort to solve my problem, I thought of using it like this:
array_push($cakes, extract($new_cakes)); //thinkin' extract would insert all elements...
But, yeah, does not work.
My mind tricked me into another funny idea which was also a big failure...
array_push($cakes, list() = $new_cakes); //it's your chance to laugh at me (n00b) now...
Q: any way to extract array elements to a list of values so they can all be passed as a row of parameters in a function?
Thanks guys