note 52627 added to function.array-search
| From: | kmkz | Date: | Sat, 07 May 2005 14:46:19 +0000 |
| Subject: | note 52627 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89077@lists.php.net to get a copy of this message | ||
I always wanted an array_replace function that could search and replace within an array, so I made
one (its kinda simple and a bit inefficient, but c'est la vie):
<?php
function array_replace($search, $replace, &$array) {
foreach($array as $key => $value) {
if($value == $search) {
$array[$key] = $replace;
}
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52627
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52627&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52627&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52627&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52627&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52627&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52627&report=yes
Search -- http://master.php.net/manage/user-notes.php