Remove those array indexes whose value is 1
array (1=>1,2=>2,3=>1,4=>1,5=>3,6=>1);
result array as
array(2=>2,5=>3);
is there is a direct function in php? like
unset(key($a,1));
look to use array_filter()
$myArray = array (1=>1,2=>2,3=>1,4=>1,5=>3,6=>1);
$myArray = array_filter(
$myArray,
function($value) {
return $value !== 1;
}
);
Loop through it, check and unset -
foreach($array as $k => $v) {
if($v == 1) {
unset($array[$k]);
}
}
Or use array_filter()
$newArr = array_filter($array, function($v) {
return ($v != 1);
});
Or you can use array_flip() for some trick -
$temp = array_flip($array);
unset($temp[1]);
$array = array_flip($temp);