Re: A php bug or?..

From: Date: Mon, 08 Aug 2011 20:34:41 +0000
Subject: Re: A php bug or?..
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-314432@lists.php.net to get a copy of this message
On Mon, Aug 8, 2011 at 16:20, Andre Polykanine <andre@oire.org> wrote: > Hi everyone, > >                            As we all know, count() returns 1 if the variable is > not an array. > Question is: why in the world does it this? If a variable is *notA* an array, it contains > *zero* array elements. > You can answer: "but no, man, you can say > $x="world"; > $y=$x{3}; // $y="l" > > so the variable is treated or can be treated as an array". > Well. If strings are treated like arrays, why count($x) doesn't return 5 instead of 1? > Just asking. Using count() will return the number of items passed in the first parameter. If it's an array, each element is an item. If it's a string, the string is an item. If it's an object, logically, the items depend on what is contained in the object. However, at no time does it return the number of characters within a string --- instead, as you likely know, you'd use strlen(). -- </Daniel P. Brown> Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/

« previous php.general (#314432) next »