Is str_replace supposed to work when the subject (haystack) is an array of arrays, not just a simple array?
Here's an example:
The above outputs:
needle1
needle2
needle3
needle4
needle5
needle6
I.e., no replacements are made.
Whereas:
outputs:
pin1
pin2
pin3
Am I doing something wrong? Is there an alternative to str_replace that will do what I want?
Here's an example:
PHP:
$old_array[0] = array("needle1","needle2","needle3");
$old_array[1] = array("needle4","needle5","needle6");
$new_array = str_replace("needle","pin", $old_array);
echo $new_array[0][0]."<br>";
echo $new_array[0][1]."<br>";
echo $new_array[0][2]."<br>";
echo $new_array[1][0]."<br>";
echo $new_array[1][1]."<br>";
echo $new_array[1][2]."<br>";
The above outputs:
needle1
needle2
needle3
needle4
needle5
needle6
I.e., no replacements are made.
Whereas:
PHP:
$old_array = array("needle1","needle2","needle3");
$new_array = str_replace("needle","pin", $old_array);
echo $new_array[0]."<br>";
echo $new_array[1]."<br>";
echo $new_array[2]."<br>";
outputs:
pin1
pin2
pin3
Am I doing something wrong? Is there an alternative to str_replace that will do what I want?