In PHP, will these always return the same values?
//example 1
$array = array();
if ($array) {
echo 'the array has items';
}
// example 2
$array = array();
if (count($array)) {
echo 'the array has items';
}
Thank you!
From http://www.php.net/manual/en/language.types.boolean.php, it says that an empty array is considered FALSE.
(Quoted): When converting to boolean, the following values are considered FALSE:
Since
then both cases illustrated in the question will always work as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With