In PHP, you can use the empty
function or check the array's length to determine if it's not empty.
In this example,
$numbers
with some elements.empty
function or by checking its length, and store the result in the variable $notEmpty
.<?php
$numbers = [1, 2, 3];
$notEmpty = !empty($numbers) || count($numbers) > 0;
echo 'Array is not empty: ' . ($notEmpty ? 'true' : 'false');
?>
Array is not empty: true
In this example,
$emptyArray
.empty
function or by checking its length, and store the result in the variable $notEmpty
.<?php
$emptyArray = [];
$notEmpty = !empty($emptyArray) || count($emptyArray) > 0;
echo 'Array is not empty: ' . ($notEmpty ? 'true' : 'false');
?>
Array is not empty: false
In this tutorial, we learned How to check if an Array is Not Empty in PHP language with well detailed examples.