Answers for "choose a random word from an array 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
0

choose a random word from an array php

<?php
// array_rand() + shuffle
$answers = Array('Hello!','Salut!','Vivat!','Chao!','Привет');
shuffle($answers);
echo $answers[array_rand($answers)];

// I use it for BotMan:
$botman->hears('Hi', function ($bot) {
    $answers = Array('Hello!','Salut!','Vivat!','Chao!','Привет');
    shuffle($answers);
    $bot->reply($answers[array_rand($answers)]);
});
Posted by: Guest on June-28-2021

Code answers related to "choose a random word from an array php"

Browse Popular Code Answers by Language