Replacing empty string with nulls in array php

As far as I know, there is no standard function for that, but you could do something like:

foreach ($array as $i => $value) {
    if ($value === "") $array[$i] = null;
}

I don't think there's such a function, so let's create a new one

$array = array(
   'first' => '',
   'second' => ''
);

$array2 = array_map(function($value) {
   return $value === "" ? NULL : $value;
}, $array); // array_map should walk through $array

// or recursive
function map($value) {
   if (is_array($value)) {
       return array_map("map", $value);
   } 
   return $value === "" ? NULL : $value;
};
$array3 = array_map("map", $array);