I have query results stored in a variable $result. I loop through $result and check for a particular key's value. If it is null, I want to have 'No' placed as value for the key 'customer'.
$result=$query->fetchAll(PDO::FETCH_ASSOC);
foreach($result as $row){
if (empty($row['customer'])) {
$row['customer'] = 'No';
}
Now, I need to create a list from the $result.
$list=array();
foreach($result as $key => $value){
$list['result'][$key] = $value;
var_dump($value);
}
But when I dump and see the values, I still see null instead of "No"
array
'name' => string 'Rachel' (length=6)
'customer' => null
array
'name' => string 'Kyndall' (length=7)
'customer' => null
Please let me know how I can have "No" as value for 'customer' key in the list if it is null. I need the list to export to csv file.
Thanks a lot.