xxxxxxxxxx
<?php
// Sample array
$array = [1, 2, 3, 4, 5];
// Get a random value
$randomValue = $array[array_rand($array)];
// Output the random value
echo $randomValue;
?>
xxxxxxxxxx
<?php
$indexedArray = array("red", "blue", "green", "black");
echo $indexedArray[array_rand($indexedArray)];
?>
xxxxxxxxxx
<?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";
?>
xxxxxxxxxx
$colors=["red","blue","green","orange"];
echo $colors[array_rand($colors)];//green (or any color randomly)
xxxxxxxxxx
$array = ["a", "b", "c"];
$random = $array[ Rand(0, count($array)-1) ];
echo $random; // a or b or c
xxxxxxxxxx
<?php
// Array of elements
$myArray = array("apple", "banana", "orange", "grape", "melon");
// Get a random element from the array
$randomElement = $myArray[array_rand($myArray)];
// Print the random element
echo $randomElement;
?>
xxxxxxxxxx
<?php
$myArray = array('apple', 'banana', 'orange', 'grape', 'kiwi');
$randomItem = $myArray[array_rand($myArray)];
echo $randomItem; // Output: Random item from the array
?>
xxxxxxxxxx
<?php
$indexedArray = array("red", "blue", "green", "black");
echo $indexedArray[0] . "<br>";
echo $indexedArray[1] . "<br><br>";
$array_random = array_rand($indexedArray, 2);
echo $indexedArray[$array_random[0]] . "<br>";
echo $indexedArray[$array_random[1]] . "<br>";
?>