I'm trying to use str_replace() to remove the "my." out of the value4 elements in an array of arrays.
However, str_replace("my.", "", $myarray); isn't changing anything.
Does str_replace() not work on two-dimensional arrays?
My sample data and coding attempt:
$array = [
[
'value1' => 'John Doe',
'value2' => 'Father',
'value3' => '',
'value4' => 'http://www.website.my.com'
],
[
'value1' => 'Jane Doe',
'value2' => 'Mother',
'value3' => '',
'value4' => 'http://www.website.my.com'
]
// ...
];
$out = str_replace('.my', '', $array);
var_export($out);
No, it works on strings, or single dimension arrays.... you could use it through the callback in an array_walk_recursive though
array_walk_recursive(
$myarray,
function (&$value) {
$value = str_replace('.my', '', $value);
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With