How would I replace any occurrence of value "FOO" with "BAR" in a nested/multidimensional php array? In my case, I'm trying to replace NAN (not a number) values with a string "NAN", but the same principles should apply. My incomplete example code:
function replaceNan($data)
{
// probably some recursion here?
}
$data = [
'foo' => NAN,
'bar' => [
'one' => 1,
'nan' => NAN
],
'baz' => 'BAZ'
];
$data = replaceNan($data);
var_dump($data);
Unless there's a core php function that will help, I assume recursion will be involved, but I just can't figure it out right now. Any help appreciated.
Edit: Just to be clear, in my example, I would want $data to be modified so it looks like:
[
'foo' => "NAN",
'bar' => [
'one' => 1,
'nan' => "NAN"
],
'baz' => 'BAZ'
]