Hey guys im trying to search an array for an value and then remove it. But im searching with a php variable and that seems to be the problem. So this is what I have so far:
if(isset($_REQUEST['Admin'])){
$arr = array('HAUGMA1', 'sdasd', 'dasdasda', 'sadasd');
$key=array_search($_REQUEST['Admin'],$arr);
if($key!==false)
unset($arr[$key]);
print_r($arr);
}
The $_REQUEST retrieves the value HAUGMA1 but when I print out the array it didn’t remove HAUGMA1 from it. What am I doing wrong? When I’m using this:
$key=array_search('HAUGMA1',$arr);
It is working.
I think the problem is in relation to the value that is coming from the
$_REQUESTvariable.I made the following test to show two questions:
First: using the
array_searchhas approximately 4x faster thanarray_filter.Second: the way that your script is, the item is removed from the array without problem. Try to debug the value that is coming from the variable
$_REQUEST