PHP

How do I check if an array in empty in php?

How do I check if an array in empty in php?


How do I check if an array in empty in php?

Even if an array seems empty like this

if($thisisarray['something'] == '') {} 

it might not seems empty enough! as there might be 0's

to do a check do it like this:
remove all 0's and '' then check for empty

$errors = array_filter($thisisarray);
if (!empty($thisisarray)) { echo 'do something'; }

array_filter() function's default behavior will remove all values from array which are equal to null0'' or false.

Published: 1st June 2016 by Gabriel Kolbe

Adverts