配列はランダムな値を受け取ります。
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->$json = <<<EOT [ {"album":"album1","truck":"truck1"}, {"album":"album1","truck":"truck3"}, {"album":"album1","truck":"truck4"}, {"album":"album1","truck":"truck6"}, {"album":"album2","truck":"truck2"}, {"album":"album2","truck":"truck3"}, {"album":"album3","truck":"truck2"}, {"album":"album3","truck":"truck5"} {"album":"album4","truck":"truck5"}, {"album":"album4","truck":"truck6"}, {"album":"album5","truck":"truck1"}, {"album":"album5","truck":"truck3"}, {"album":"album6","truck":"truck2"}, {"album":"album6","truck":"truck3"}, {"album":"album6","truck":"truck4"}, {"album":"album7","truck":"truck2"}, {"album":"album7","truck":"truck5"}, {"album":"album7","truck":"truck6"} ] EOT; $data = json_decode($json); foreach($data as $row){ //echo '唱片:'.$row->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]->アルバム.' 、トラック:'.$data[$k]->トラック.'<br /> <div class="clear"></div>