For example:
$product = new Product("cat");
if(isset($sales[$product])){
$sales[$product]++;
}
else{
$sales[$product] = 1;
}
See Question&Answers more detail:osFor example:
$product = new Product("cat");
if(isset($sales[$product])){
$sales[$product]++;
}
else{
$sales[$product] = 1;
}
See Question&Answers more detail:osFrom the docs:
Arrays and objects can not be used as keys. Doing so will result in a warning: Illegal offset type.
You could give each instance a unique ID or override __toString()
such that it returns something unique and do e.g.
$array[(string) $instance] = 42;