在PHP中,这些值总是会返回相同的值吗?
//example 1
$array = array();
if ($array) {
echo 'the array has items';
}
// example 2
$array = array();
if (count($array)) {
echo 'the array has items';
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
gah*_*ooa 21
来自http://www.php.net/manual/en/language.types.boolean.php,它表示空数组被视为FALSE.
(引用):转换为布尔值时,以下值被视为FALSE:
以来
然后问题中说明的两个案例将始终按预期工作.
那些总是会返回相同的值,但我发现
$array = array();
if (empty($array)) {
echo 'the array is empty';
}
Run Code Online (Sandbox Code Playgroud)
更具可读性。