PHP Recursive Replace
248
PHP Recursive replace for any type of object
EXAMPLE USAGE:
$map = ['a' => 'x',
'b' => 'y',
'c' => 'z'];
$aArray = ['a', 'b', 'c', 'p' => ['a', 'b']];
replace($aArray, $map);
// Result ['x', 'y', 'z', 'p' => ['x', 'y']];
class Test
{
public $aValue;
public $aArray;
}
$t1 = new Test();
$t1->aValue = 'c';
$t1->aArray = ['a', 'b', 'c'];
replace($t1, $map);
/** object(Test)#3 (2)
{
["aValue"]=>
string(1) "z"
["aArray"]=>
array(3) {
[0]=>
string(1) "x"
[1]=>
string(1) "y"
[2]=>
string(1) "z"
}
}
If you are looking for consultation, fill the Contact Form below.
Peace at home, peace in the world.
Haluk YAMANER
Founder @ Future Software UAE
Founder @ Future Linux
Click here for more about me »