How can i add values to an array that is being contained by another array?
In the example code below, i am trying to add the string 'yellow' to both the arrays stored by $arr
to form [ [ 'blue',yellow'] , ['green','yellow'] ]
In the first foreach loop, the word yellow has been successful pushed into the contained array which can be seen when i print out the array $key however
when i were to print the $arr out in the final foreach loop the yellow that i appended is gone
$arr = array(array("blue"),array("green"));
foreach ($arr as $key)
{
array_push($key,"yellow");
print_r($key);
}
foreach ($arr as $key)
{
print_r($key);
}
?>