How to convert all NULL values in an array to an empty string? [duplicate]

     
  

This question already has an answer here:

     
  

I have an array called $whereClauses and I'm trying to convert any NULL values within the array to empty strings. I found this code below from a previous question on stackoverflow but I can't figure out how to apply it to my array. Any help would be much appreciated.


I have updated the code to show what I am doing.


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

//Updated code


if (isset($_POST['btn'])) {
   $whereClauses = array();    if (! empty($_POST['location'])) $whereClauses[] ="(location ='".mysqli_real_escape_string($db_conx$_POST['location'])."')";
$whereClauses[] ="(activated='1')";
   //Convert Null values to empty strings   foreach ($whereClauses as $key => $value) {   if (is_null($value)) {   $whereClauses[$key] = "";   }
}   var_dump($whereClauses);
}  

Output:


array(2) { [0]=> string(18) "(location ='null')" [1]=> string(15) "(activated='1')" }  
  
"
answer1
  
  

The code snipped seems to be the right direction