I would like to get the count (total) of values in my foreach loop which share the same 'Model' and 'Condtion'.
To help you understand better, here is a representation of how my data looks like
Product Name | Condition
---------------------------------------
iPhone 3G 16GB | Used
iPhone 3G 16GB | Used
iPhone 3G 16GB | New
Blackberry 9900 | New
Blackberry 9900 | New
My current foreach loop:-
$results = getProducts();
foreach ($results as $result) {
$data[] = array (
'model' => $result['model'],
'condition' => $result['condition']
);
}
This is what I get with my current foreach loop:-
Array (
[0] => Array
(
[model] => iPhone 3G 16GB
[condition] => Used
)
[1] => Array
(
[model] => iPhone 3G 16GB
[condition] => Used
)
[2] => Array
(
[model] => iPhone 3G 16GB
[condition] => New
)
[3] => Array
(
[model] => Blackberry 9900
[condition] => New
)
[4] => Array
(
[model] => Blackberry 9900
[condition] => New
)
)
Here is how and what I would like to get instead:-
Array(
'Apple iPhone 3G 16GB' => Array (
'Used' => 2,
'New' => 1
)
'Blackberry 9900' => Array (
'New' => 2
)
)
Hope you get an idea of what I'm trying to accomplish here. Please let me know if you would like me to provide any additional info.