Home  >  Article  >  Backend Development  >  How to determine whether an array is empty in php

How to determine whether an array is empty in php

王林
王林forward
2020-07-10 17:32:114830browse

How to determine whether an array is empty in php

If you want to determine whether an array is empty in php, you can use the empty() function or the count() function.

If you want to know more related knowledge, please visit php Chinese website.

1. Use the "empty()" function to judge and pass the array into this function. If it is true, it means it is empty;

$arr = [];
if (empty($arr)) {
 //为空
} else {
 //不为空
}

2. Through "count()" function to get the number of array items, and then determine 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 {
 //不为空
 }

The above is the detailed content of How to determine whether an array is empty in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete