I am trying to loop through an array and replace values that are in_array of a different array.
$array = array("username"=>"Bill", "email" => "Email Address");
$unset = array("Username","Email Address"); // Array of default values for inputs
foreach($array as $key => $value) {
global $unset;
if(in_array($value, $unset)) {
$value = "-";
}
}
print_r($array["email"]);
I want to replace the value in $array in which matches a default value to "-". Not looking to unset and array_splice, hold the space.
foreach($array as $key=>&$value)-- note the ampersand. remember tounset($value)after the loop if you do this though, lest you accidentally overwrite the lest element later.$valuea reference to the original item in the array. without it you're essentially just editing a copy.