On 9/08/2011, at 8:20 AM, Andre Polykanine 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. > > -- > With best regards from Ukraine, > Andre I'm assuming it has to do with the value, if not an array or object, being cast as an array. Thus, non-false equivalent values get cast into an array of size 1: <?php var_dump((array)1); var_dump((array)null); // Output array(1) { [0]=> int(1) } array(0) { } --- Simon Welsh Admin of http://simon.geek.nz/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php