Let's take the following multidimensional array example:
$table=array(
"phone"=>array("value"=>"value 1", "message"=>"message 1"),
"email"=>array("value"=>"value 2", "message"=>"message 2"),
"passwd"=>array("value"=>"value 3", "message"=>"message 3")
);
print_r will display:
Array ( [phone] => Array ( [value] => value 1 [message] => message 1 ) [email] => Array ( [value] => value 2 [message] => message 2 ) [passwd] => Array ( [value] => value 3 [message] => message 3 ) )
I need a function that will empty all the "value" and "message" keys, so that print_r will now display:
Array ( [phone] => Array ( [value] => [message] => ) [email] => Array ( [value] => [message] => ) [passwd] => Array ( [value] => [message] => ) )
I tried with the following:
function recursively_erase($table){
foreach($table as $row=>$array)
foreach($array as $key=>$value)
$value="";
}
But it's not working. Has someone a better idea ?
Thanks
foreach($array as $key=>&$value) $value="";
Notice the&
.