The usual approach to this problem is to use a recursive function .
Release step by step:
First you need a control instruction foreach...
http://php.net/manual/en/control-structures.foreach.php
.. which allow you to parse an associative array without knowing the key names in advance.
Then is_arrayand is_string(and, finally is_object, is_integer...), you can check the type of each value, so you can act correctly.
http://php.net/manual/en/function.is-array.php
http://php.net/manual/en/function.is-string.php
If you find the string to be used, then you are doing the replacement task
If you find an array, the function calls the transmitting array itself, which is simply parsed.
, -.
:
function findAndReplaceStringInArray( $theArray )
{
foreach ( $theArray as $key => $value)
{
if( is_string( $theArray[ $key ] )
{
if( $key == 'name' && $theArray[ $key ] == "John" )
{
$theArray[ $key ] = "Mike";
}
}
else if( is_array( $theArray[ $key ] )
{
$nestedArray = $theArray[ $key ];
findAndReplaceStringInArray( $nestedArray );
}
}
}