I'm trying to add key value pairs to an array with php.
When I echo out the array, i get the values
echo "Key = " . $key . "| Value = " . $value;
Key = area_id| Value = 4000001Key = area_title| Value = Region
All good.
But when I try and add those key value pairs to an array 'main', the array is empty?
Like below:
$main = array();
function recursive($array){
foreach($array as $key => $value){
//If $value is an array.
if(is_array($value)){
//We need to loop through it.
recursive($value);
} else{
//It is not an array, so print it out.
//$main[$key] = array (
// $key = $value
//);
//echo "Key = " . $key . "| Value = " . $value;
$main[$key] = $value;
}
}
}
If the key and values are there, as I can echo them, why are they not adding to the array?