I've tried the following to remove the null values from a resultset.
if((is_null($value)) || ('NULL' === $value) || (null === $value))
none seem to be working.
Here's my full code:
// remove null values from contact details
$contactData[$key] = removeEmptyDataFromArray($contact);
print "<pre>".print_r($contactData[$key],true)."</pre">;
// remove empty data function
function removeEmptyDataFromArray(array $filledData)
{
foreach ($filledData as $key => $value )
{
if ((is_null($value)) || (strlen ( $value ) === 0) || ('NULL' == $value) || (NULL === $value))
{
unset ( $filledData [$key] );
}
}
return $filledData;
}
And here are the results from my print_r:
firstname :
lastname :
middlename :
primary_emailaddress : [email protected]
var_dump/print_rto see what exactly is the data you are getting from your query. Then look intoempty,is_nullto see what serves your purpose.'NULL' === $valueis not the way to check for NULL. Also, make sure you are checking against the correct value, like do you need to use an array index for the particular value, rather than the complete response from query?