Home >> Snippet List >> Snippet

Name
Unset unkown array element
Description
Given the array "1,2,3,4", let's say you want to delete the "3" You know the value of the array element, but not the position Here's how you can do it
PHP Snippet
$a =  ARRAY(1,2,3,4);
 
IF(($key = ARRAY_SEARCH(3, $a, TRUE)) !== FALSE){
 
      UNSET($a[$key]);
 
}