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.
Never Miss an Articles from us.
The program in Php to check whether a number is prime or not is as follows : <?php function primeCheck($number){ if ($number == 1) return 0; for ($i =...
The program to find no of days between two dates in PHP is as follows: Let the dates are 25-09-2020 and 31-01-2021 <?php function dateDiffInDays($date1, $date2) { &nbs...
The program in PHP to find the occurrence of a word in a string is as follows: <?php $s1 = "interviewmocks.com is a interview prep site"; $s2 = "interview"; $res = substr_count($s1, $s2); echo...