我是 php 新手。
当 iprint_r($documents)
时,系统会显示:
数组 ( [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 [主题] => 技术))
我想计算“主题”并在该对象上找到最高“分数”,所以我有一个结果:
主题“技术”= 4 个文档
主题“食物”= 1 个文档
文档“AAA”中的最高分 = 100
我可以用 foreach 函数做什么?
foreach($documents as $data)
{
$id = $data->id;
$title = $data->title;
$score = $data->score;
$topic = $data->topic;
}
谢谢你的帮助。