Heim >Backend-Entwicklung >PHP-Tutorial > 数组随机取值。解决方案
数组随机取值。
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->$json = album.' ,曲目:'.$row->truck.'<br>'; }
$data = json_decode($json); foreach($data as $v) $r[$v->truck] = $v; $data = $r; $ar = array_rand($data, 4); foreach($ar as $k) { echo '唱片:'.$data[$k]->album.' ,曲目:'.$data[$k]->truck.'<br>'; } <div class="clear"> </div>