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

How to determine if an array is not empty in php

Guanhui
GuanhuiOriginal
2020-05-09 17:47:533132browse

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!

Statement:
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