Changing the resulting array values ​​in PHP

I am trying to change the values ​​of a recursevely array, and all the examples that I have seen on stackoverflow are not suitable for what I want so far.

Basically, I want to translate a boolean into String.

foreach($this->data as $key=>$value) { if (is_bool($value)) { $this->data[$key] = var_export($value, true); } } 

This only works on the first level of the array. Also, I tried changing the values ​​with array_walk_recursive without success.

Thanks in advance.

+5
source share
1 answer

array_walk_recursive () should do this quite easily

 array_walk_recursive( $myArray, function (&$value) { if (is_bool($value)) { $value = 'I AM A BOOLEAN'; } } ); 

Demo version

+12
source

All Articles