I have an empty array that I am trying to push a value to via a simple php function. The problem is that within each iteration the values are not being retained. Here is an example:
function addColors($arrayValues, $arrayToUpdate){
$arrayToUpdate[]=$arrayValues;
}
$colors = array();
$newColors= array("red", "blue", "yellow");
foreach($newColors as $newColor){
addColors($newColor, $colors);
}
echo "<pre>".print_r($colors, true)."</pre>";
This will just print an empty array. Whereas what I would like to see are the values being added to the $colors array. Any suggestions?
$arrayToUpdateand$newColorin function definitions to keep it as reference.function addColors($arrayValues, &$arrayToUpdate){