note 24380 added to function.array-count-values
| From: | jon at fuck dot org | Date: | Wed, 14 Aug 2002 18:31:25 +0000 |
| Subject: | note 24380 added to function.array-count-values | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35018@lists.php.net to get a copy of this message | ||
suggested plan of attack:
<pre>
<?
class MyObject {
function MyObject($t = 'none')
{
$this->$myTag = $t;
}
}
$myArray = array();
for ($i = 1 ; $i < 11 ; $i++)
{
$myobj = new MyObject( str_pad('n', $i, 'x') );
$myArray[ $myobj->$myTag ] = $myobj;
}
print_r( array_count_values(array_keys($myArray)) );
?>
to sum up:
assuming each instance of an object you create has some sort of tag, e.g.,
$this->$myTag=get_class($this)
..you should be set. objects dont have value to compare the way strings and integers do, so,
$myTag's value is arbitrary.
--
http://www.php.net/manual/en/function.array-count-values.php
http://master.php.net/manage/user-notes.php?action=edit+24380
http://master.php.net/manage/user-notes.php?action=delete+24380
http://master.php.net/manage/user-notes.php?action=reject+24380