March 10, 2013

Why count(false) return 1?

Question by Jeremie Ges

Do you know why <?= count(false) ?> return 1 ?

Thank’s in advance.

Answer by Starx

Because false is also a value and if the count() does not get array but a valid variable it returns true which is 1.

$result = count(null);
// $result == 0

$result = count(false);
// $result == 1

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!