Barrucadu Established Member ★ 20 ★ Impact 64 Sep 12, 2006 642 views 4 replies #1 Get 5 random values from an array? And display them in alphabetical order.
Noobie Established Member ★ 15 ★ Impact 11 Sep 12, 2006 #2 PHP: asort(array_rand($myarray, 5)); // for sorting values ksort(array_rand($myarray, 5)); // for sorting keys You can use sort() but it rewrites the keys Last edited: Sep 12, 2006
PHP: asort(array_rand($myarray, 5)); // for sorting values ksort(array_rand($myarray, 5)); // for sorting keys You can use sort() but it rewrites the keys
Barrucadu Established Member ★ 20 ★ Impact 64 Sep 12, 2006 #3 PHP: asort(array_rand($videos, 5)); just returns the first 5 videos (ie: not choosing 5 random ones)
Noobie Established Member ★ 15 ★ Impact 11 Sep 12, 2006 #4 dunno, the function is array_rand, i use it quite alot. try it without the sorts PHP: $arr = array('dog','cat','cow','horse','fish'); $rnd =(array_rand($arr,2)); echo $arr[$rnd[0]] . "<br/>"; echo $arr[$rnd[1]] . "<br/>"; then try this PHP: $arr = array('dog','cat','cow','horse','fish'); $rnd =(array_rand($arr,2)); foreach($rnd as $a){ $temp[] = $arr[$a]; } asort($temp); print_r($temp); Last edited: Sep 12, 2006
dunno, the function is array_rand, i use it quite alot. try it without the sorts PHP: $arr = array('dog','cat','cow','horse','fish'); $rnd =(array_rand($arr,2)); echo $arr[$rnd[0]] . "<br/>"; echo $arr[$rnd[1]] . "<br/>"; then try this PHP: $arr = array('dog','cat','cow','horse','fish'); $rnd =(array_rand($arr,2)); foreach($rnd as $a){ $temp[] = $arr[$a]; } asort($temp); print_r($temp);