I have one array with state codes and their full names, like this:
$first_array=array("AB"=>"Alberta","BC"=>"British Columbia");
I have another array with ids and state codes, like this:
$result_array=array(15=>array("ad_id"=>15,"state code"=>"AB"));
I want to replace the state code values in $result_array with the corresponding "full name" in $first_array.
If there is no corresponding value in $first_array then the state code in $result_array should remain unchanged.
This is my expected result:
$result_array=array(15=>array("ad_id"=>15,"state code"=>"Alberta"));
array_search()for finding key value and replace it with another variablearray_walk($resultArray, function (&$value) use ($first_array) { $value['state_code'] = $first_array[$value['state_code']]; });array_walkis better. Missed it. :)