Re: A php bug or?..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 8, 2011 at 16:20, Andre Polykanine <andre@xxxxxxxx> 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/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux