For example:
$product = new Product(\"cat\");
if(isset($sales[$product])){
$sales[$product]++;
}
else{
$sales[$product] = 1;
}
You could have two arrays:
Array 1 contains the keys: | Array 2 contains the values
+--------+-------------+ | +--------+------------+
| index: | value: | | | index: | value: |
| 0 | Object(key) | | | 0 | sth(value) |
| 1 | Object(key) | | | 1 | sth(value) |
+--------+-------------+ | +--------+------------+
You search for the Object in array 1,
then you pick the index of that Object
use it as index for array 2 and
=> get the value
in php code
public function getValue($ObjectIndexOfYourArray){
foreach(array1 as $key => $value) {
if($value == ObjectIndexOfYourArray){
return array2[$key];
}
}
}
I hope it helps