I'm new in php.
When i print_r($documents)
, the system will display:
Array ( [0] => stdClass Object ( [id] => 1 [title] => "AAA" [summary] => blablabla [score] => 100 [topic] => Technology ) [1] => stdClass Object ( [id] => 2 [title] => "BBB" [summary] => blablabla [score] => 86 [topic] => Food ) [2] => stdClass Object ( [id] => 3 [title] => "CCC" [summary] => blablabla [score] => 45 [topic] => Technology ) [3] => stdClass Object ( [id] => 4 [title] => "DDD" [summary] => blablabla [score] => 67 [topic] => Technology ) [4] => stdClass Object ( [id] => 5 [title] => "EEE" [summary] => blablabla [score] => 88 [topic] => Technology ))
I want to count 'topic' and find a highest 'score' on that object, so i have a result:
Topic "Technology" = 4 documents
Topic "Food" = 1 document
Highest score = 100 in document "AAA"
What can i do with foreach function?
foreach($documents as $data)
{
$id = $data->id;
$title = $data->title;
$score = $data->score;
$topic = $data->topic;
}
Thanks for your help.