How do I check that a PHP array is not empty?
// If $columns array is not empty...
foreach ($columns as $column) {
echo $column;
}
How do I check that a PHP array is not empty?
// If $columns array is not empty...
foreach ($columns as $column) {
echo $column;
}
Why bother with functions? Empty arrays will simply return false:
if ($array) {
// array is not empty
}
One way is to use count()
if (count($columns) > 0) {
foreach ($columns as $column) {
echo $column;
}
}
Very simple: using empty()
function.
if (!empty($columns)){
foreach ($columns as $column) {
echo $column;
}
}
Also can be used with other types than array.