Gordon Bean
0
Q:

php get random element from array

$items = array(1, 2, 3, 4, 5);
echo $items[array_rand($items)];
1
<?php
//array_rand ( array $array [, int $num = 1 ] ) 
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";
?>

1
array_rand(array, number)
0

New to Communities?

Join the community