very nice explanation! On Wed, Nov 27, 2013 at 8:49 PM, Sebastian Krebs <krebs.seb@xxxxxxxxx>wrote: > 2013/11/27 Daevid Vincent <daevid@xxxxxxxxxx> > > > > > > > > -----Original Message----- > > > From: Aziz Saleh [mailto:azizsaleh@xxxxxxxxx] > > > Sent: Wednesday, November 27, 2013 10:15 AM > > > To: Daevid Vincent > > > Cc: php-general@xxxxxxxxxxxxx > > > Subject: Re: echo count(false); == 1 ?! > > > > > > On Wed, Nov 27, 2013 at 1:04 PM, Daevid Vincent <daevid@xxxxxxxxxx> > > wrote: > > > > > > > Really? 1?? I would have expected 0 or false or something other than > > > > positive. *sigh* > > > > > > > > $ php -a > > > > php > echo count(false); > > > > 1 > > > > > > > > > > > > :-\ > > > > > > > http://us3.php.net/count > > > > > > The manual is a great place to figure out why things happen a certain > > way. > > > > The manual page does not explain WHY that logic is used and even > > inconsistent since null returns 0. It only says that it does return 1. > > > > Actually it does, but on a different page [1], because at the end it > behaves like "count((array) $foo)" > > > For any of the types: integer, float, string, boolean and resource, > converting a value to an array results in an array with a single element > with > > index zero and the value of the scalar which was converted. In other > words, (array)$scalarValue is exactly the same as array($scalarValue). > > And some lines below > > > Converting NULL to an array results in an empty array. > > > [1] php.net/language.types.array.php#language.types.array.casting > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > github.com/KingCrunch >