Example array
$myArray[0] = array('23', null, '43', '12');
$myArray[1] = array(null, null, '53', '19');
$myArray[2] = array('12', '13', '14', null);
All nulls should be replaced with 0. I was hoping someone would have an efficient way of doing this, perhaps a built in PHP function that I am unaware of.
You could use the
array_walk_recursivefunction, with a callback function that would replacenullby0.For example, considering your array is declared this way :
Note : I supposed you made a typo, and your arrays are not containing only a string, but several sub-elements.
You could use this kind of code :
With the following callback functon :
Note that :
===operator for the comparisonAnd you’d get the following output :