Home > Backend Development > PHP Tutorial > Code to determine whether a PHP array is empty_PHP Tutorial

Code to determine whether a PHP array is empty_PHP Tutorial

WBOY
Release: 2016-07-21 15:24:30
Original
724 people have browsed it

PHP's preferred method to determine if an array is empty: count($arr),size($arr);

Copy code The code is as follows:

$arr= array("");
echo count($arr);
echo size($arr);
//Output 1

Copy code The code is as follows:

$arr= array();
echo count($arr);
echo size($ arr);
//Output 0


PHP method 2 to determine if the array is empty: empty($arr);
Copy code The code is as follows:

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


These two methods are sufficient for simple arrays and To determine whether a multi-dimensional array is empty, I generally use empty() to determine if the array is not empty, so that the code looks easier to understand.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324276.htmlTechArticlePHP preferred method to determine if an array is empty: count($arr),size($arr); Copy the code as follows : $arr= array(""); echo count($arr); echo size($arr); //Output 1 Copy the code as follows: $arr=...
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