note 105713 modified in function.count by danbrown
| From: | danbrown@php.net | Date: | Thu, 08 Sep 2011 17:37:16 +0000 |
| Subject: | note 105713 modified in function.count by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183053@lists.php.net to get a copy of this message | ||
If you try to do a sizeof or count with an object, it will always return 1 if the object is not
null.
You need to type cast the object as an array for it to count correctly.
ex:
<?php
$obj->foo = 'fu';
$obj->bar = $fooBar();
echo count($obj); //returns 1
echo count( (array) $obj); // returns 2
?>
--was--
If you try to do a sizeof or count with an object, it will always return 1 if the object is not
null.
You need to type cast the object as an array for it to count correctly.
ex:
$obj->foo = 'fu';
$obj->bar = $fooBar();
echo count($obj); //returns 1
echo count( (array) $obj); // returns 2
http://php.net/manual/en/function.count.php