我有这个代码json代码[{"title":"Title 1","option":"Option 1"},{"title":"title 2","option":"Option 2"}]我用它来显示它foreach ($query->getResult() as $row) { foreach (json_decode($row->keywords) as $msg) { echo $msg->title . "<br/>" . $msg->option . "<hr/>"; }}我怎样才能随机显示这个?
1 回答
德玛西亚99
TA贡献1770条经验 获得超3个赞
您可以提取关键字数组,然后在显示前对其进行打乱:
foreach ($query->getResult() as $row) {
$keywords = json_decode($row->keywords);
shuffle($keywords);
foreach ($keywords as $msg) {
echo $msg->title . "<br/>" . $msg->option . "<hr/>";
}
}
- 1 回答
- 0 关注
- 78 浏览
添加回答
举报
0/150
提交
取消