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

How to determine whether an array is empty in php

王林
Release: 2023-03-02 11:00:02
forward
4872 people have browsed it

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 {
 //不为空
}
Copy after login

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 {
 //不为空
 }
Copy after login

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template