-3

What does if ($array){ } condition mean in php?

When is it true or false?

Vpant
  • 321
  • 1
  • 5
  • 15
  • 3
    http://php.net/manual/en/language.types.boolean.php#language.types.boolean.casting – Jeto Apr 15 '18 at 11:36
  • 2
    Possible duplicate of [Regarding if statements in PHP](https://stackoverflow.com/questions/6554384/regarding-if-statements-in-php) – Pradeep Apr 15 '18 at 11:51

1 Answers1

2

The array will be casted to a boolean, like if you would use if((bool) $array) { }

false is returned when the array is empty (e.g. $array = [])

true is returned as soon as at least one key is set in the array (either like ["some value"] or ["data" => "value"]

You can simply test what the returned value will be by using

var_dump((bool) $your_array);

webFashion
  • 748
  • 9
  • 17