Looking to Build/Redesign a Website or Blog ?

To speak to Rakshit, call +91 968 704 2303

Remove Empty/Null Rows from array using PHP

Hello Friends,

I got so many empty element as well as null values in array and my SQL query is some what complex so i was not able to use IS NOT NULL in mysql Query. Only alternative way i have is removing this null values from array using PHP. I used is_null function of PHP and remove null elements from array. Be careful with “” and null as they are two different things. I you want to remove empty elements as well than you can use one more condition along with is_null. Look at below code. I hope this helps you a little.

 foreach ($rec as $key=>$value)  
  if (is_null($value['column_name'])) 
  { // Check for null value of column
   unset($rec[$key]); // remove row from array if null element found

Let me know if you have any problem.

Thank You!


1 Comment

Leave a Reply

Your email address will not be published.