I'm trying to change the values of an array recursevely and all the examples that I've seen in stackoverflow don't fit for what I want so far.
Basically, I want to translate a boolean to String.
foreach($this->data as $key=>$value)
{
if (is_bool($value))
{
$this->data[$key] = var_export($value, true);
}
}
This works just in the first level of the array. Also, I've tried to change the values with array_walk_recursive
with no success as well.
Thanks in advance.
array_walk_recursive() should do this perfectly easily
array_walk_recursive(
$myArray,
function (&$value) {
if (is_bool($value)) {
$value = 'I AM A BOOLEAN';
}
}
);
Demo
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