Write a PHP function to convert all null values to blank?

devquora
devquora

Posted On: Feb 22, 2018

 

When we are outputting our results into JSON for purpose of web services then It is a good practice to convert all null value to an empty string, below is simple PHP function to convert all null values to blank.


function convertNullToBlank($array){

foreach ($array as $key => $value) {
if (is_null($value)) {
$array[$key] = "";
}
}
return $array;

}

Above function takes an array as an argument and converts it all null values to blank.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions