Home >Backend Development >PHP Problem >How to determine if an array is not empty in php
How to determine if the array is empty in php
1. Use the function "empty()" to determine and pass the array into this function , if it is true, it means it is empty;
$arr = []; if (empty($arr)) { //为空 } else { //不为空 }
2. Use the "count()" function to get the number of array items, and then judge whether it is less than 1 based on the number of items. If it is less than 1, it means it is empty;
$arr = []; if (count($arr) < 1) { //为空 } else { //不为空 }
Recommended tutorial: "PHP Tutorial"
The above is the detailed content of How to determine if an array is not empty in php. For more information, please follow other related articles on the PHP Chinese website!