$fields = array('timbo', '22', 'norway');
How could I unset the array key for norway based on it's value alone?
$fields = array('timbo', '22', 'norway');
How could I unset the array key for norway based on it's value alone?
$key = array_search( 'norway', $fields );
if ($key !== FALSE) {
unset($fields[$key]); // remove
}
You could use array_search to get the index. array_search
will exit after the first match.
$index = array_search('norway', $fields);
if($index !== FALSE)
unset($fields[$index]);