PHP - Replace data within multidimensional array, specific key
foreach($array as &$value) {
$value['ad_type'] = 'new value';
}
Best way to access the keys and values of an array is with foreach loop.
Something like:
$array= Array ( [13] => Array ( [ad_id] => 13 [ad_name] => Qhxxst [ad_link] => www.qxxst.co.uk [ad_type] => 1 ) [15] => Array ( [ad_id] => 15 [ad_name] => Pxxly [ad_link] => http://pixxly.net [ad_type] => 1 ) [16] => Array ( [ad_id] => 16 [ad_name] => cxxm [ad_link] => http://www.cxxm.co.uk [ad_type] => 1 ) );
foreach ($array as $key=>$val)
{
if ($key=="ad_type" && $val==1)
{
$val="x";
}
elseif ($key=="ad_type" && $val==2)
{
$val="y";
}
}
For further reference http://php.net/manual/en/control-structures.foreach.php