How to check if an array is empty
Short answer
Compare the array with an empty array:
<?php
$items = [];
var_dump($items === []);Output:
bool(true)With count
The number of elements is zero:
<?php
$items = [];
var_dump(count($items) === 0);Output:
bool(true)In a condition
An empty array counts as false in a condition, so the check can be written briefly:
<?php
$items = [];
echo $items ? 'has items' : 'empty';Output:
empty