Answers for "array random php"

PHP
4

choose a random word from an array php

$items = array(1, 2, 3, 4, 5);
echo $items[array_rand($items)];
Posted by: Guest on June-27-2020
5

php get random element from array

<?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";
?>
Posted by: Guest on June-20-2020
1

random array php

$array = ["a", "b", "c"];
$random = $array[ Rand(0, count($array)-1) ];

echo $random; // a or b or c
Posted by: Guest on August-17-2021
2

php get random value from array

$colors=["red","blue","green","orange"];
echo $colors[array_rand($colors)];//green (or any color randomly)
Posted by: Guest on June-02-2021
1

array random php

<?php
$indexedArray = array("red", "blue", "green", "black");
echo $indexedArray[array_rand($indexedArray)];
?>
Posted by: Guest on September-11-2021
0

array random php

<?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>";
?>
Posted by: Guest on September-11-2021

Browse Popular Code Answers by Language