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

How to determine if an array is not empty in php

Guanhui
Release: 2023-03-01 07:02:02
Original
3248 people have browsed it

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

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

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!

Related labels:
source:php.cn
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