Two examples of php judging that the array is empty_PHP tutorial

WBOY
Release: 2016-07-13 16:59:23
Original
860 people have browsed it

The following provides two PHP codes that determine whether the array is empty. Because the array is a composite data type, we cannot process it like other character data. See examples below.

Method
1. Use count (array) to get records. Empty returns 0
2. Use is_null function

The code is as follows
 代码如下 复制代码

$a=array('1','2','3');
echo count($a);


if(is_null($a)){
echo '000';
}else{
echo "1111";
}
?>

Copy code


$a=array('1','2','3');

echo count($a);


if(is_null($a)){
代码如下 复制代码
/**
array(
); 空
array(
array(
),
array(
),
array(
)
); 空
array(
array(
),
array(
array(
),
array(
1=>1
)
),
array(
)
); 非 空
*/
function is_array_null($value)
{
if (empty($value))
{
return $value;
}
else
{
return is_array($value) ? array_map('array_null', $value) : addslashes($value);
}
}
echo '000'; }else{ echo "1111"; } ?>

The count method is feasible The is_null method does not work Example 2 //Determine whether an array is empty
The code is as follows Copy code
/** array( ); 空
array(
array( ), array( ), array( ) ); 空 array( array( ), array( array( ), array( 1=>1 ) ), array( ) ); 非 空 */ function is_array_null($value) { if (empty($value)) { return $value; } else { return is_array($value) ? array_map('array_null', $value) : addslashes($value); } } http://www.bkjia.com/PHPjc/631319.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631319.htmlTechArticleThe following provides two PHP codes that determine whether the array is empty, because the array is a composite data type and we cannot It is processed like other character data, see examples below. Method 1. Use cou...
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