note 121096 deleted from function.str-replace by cmb
| From: | cmb@php.net | Date: | Sun, 15 Sep 2019 14:49:10 +0000 |
| Subject: | note 121096 deleted from function.str-replace by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212213@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
As others have written, the replaced part can be replaced again if one uses an associative array. If
you simply want to replace a certain string with another one, this will work instead:
$string = 'A';
$replace = array( 'A' => 'B', 'B' => 'C');
foreach ($replace as $arraykey => $arrayvalue)
{
if ($string === $arraykey)
{
$string = $arrayvalue;
break;
}
}
$string2 = 'A';
$string2 = str_replace(array_keys($replace), $replace, $string2);
echo $string; // B
echo $string2; // C