How to determine whether an array is empty in php

(*-*)浩
Release: 2023-02-27 19:20:01
Original
4284 people have browsed it

How to determine whether an array is empty in php

PHP’s preferred method to determine if an array is empty:count($arr),size($arr); (Recommended learning:PHP video tutorial

Just use this function count. If the output is 0, then the array is empty. The following is a simple test code.

$arr= array(""); echo count($arr); echo size($arr); //输出1 $arr= array(); echo count($arr); echo size($arr); //输出0
Copy after login

PHP method to determine if an array is empty: empty($arr);

empty() The function is to determine whether the variable is empty. If the variable = empty, it returns TRUE , if it is not empty, return FALSE (not an empty value)

$arr= array(""); $result = empty($arr); //$result = false $arr = array(); $result = empty($arr); //$result = true
Copy after login

Are these two methods sufficient to deal with the problem of judging whether simple arrays and multi-dimensional arrays are empty? Personally, I generally use empty() to judge whether the array is empty. , so that the code looks easier to understand.

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:
php
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!