note 119796 rejected from function.unset by cmb

From: Date: Sun, 28 Aug 2016 14:23:55 +0000
Subject: note 119796 rejected from function.unset by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-206410@lists.php.net to get a copy of this message
Note Submitter: goran77 at fastmail dot fm ---- $a = ['x', 'y']; // we are looking for index of 'x', // and we are getting 0 as result $index = array_search('x', $a); // this removes element with index 0 ('x'). So far so good. unset ($a[$index]); print_r ($a); // Array ( [1] => y ) // BUT, if we were looking for non-existent element, // we'll get FALSE as result... $a = ['x', 'y']; $index = array_search('z', $a); //here $index is false, not zero // ...but it will also remove 'x' unset ($a[$index]);

« previous php.notes (#206410) next »