note 77005 modified in function.str-replace by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 16:16:13 +0000 |
| Subject: | note 77005 modified in function.str-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142171@lists.php.net to get a copy of this message | ||
This is the functions I wrote for the problem reported above, str_replace in multi-dimensional
arrays. It can work with preg_replace as well.
<?php
function array_replace($SEARCH,$REPLACE,$INPUT) {
if (is_array($INPUT) and count($INPUT)<>count($INPUT,1)):
foreach($INPUT as $FAN):
$OUTPUT[]=array_replace($SEARCH,$REPLACE,$FAN);
endforeach;
else:
$OUTPUT=str_replace($SEARCH,$REPLACE,$INPUT);
endif;
return $OUTPUT;
}
?>
--was--
This is the functions I wrote for the problem reported above, str_replace in multi-dimensional
arrays. It can work with preg_replace as well.
function array_replace($SEARCH,$REPLACE,$INPUT) {
if (is_array($INPUT) and count($INPUT)<>count($INPUT,1)):
foreach($INPUT as $FAN):
$OUTPUT[]=array_replace($SEARCH,$REPLACE,$FAN);
endforeach;
else:
$OUTPUT=str_replace($SEARCH,$REPLACE,$INPUT);
endif;
return $OUTPUT;
}
http://php.net/manual/en/function.str-replace.php