note 22605 added to function.array-search

From: Date: Mon, 24 Jun 2002 18:03:20 +0000
Subject: note 22605 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-32159@lists.php.net to get a copy of this message
Here's how you can use array_search() to replace all occurances of a value in an array: function array_replace($a, $tofind, $toreplace) { $i = array_search($tofind, $a); if ($i === false) { return $a; } else { $a[$i] = $toreplace; return array_replace($a, $tofind, $toreplace); } } Usage: $a = array(1,2,3); $a = array_replace($a, 1, 4); echo $a[0]; // Outputs 4 -- http://www.php.net/manual/en/function.array-search.php http://master.php.net/manage/user-notes.php?action=edit+22605 http://master.php.net/manage/user-notes.php?action=delete+22605 http://master.php.net/manage/user-notes.php?action=reject+22605

« previous php.notes (#32159) next »