Answer the question
In order to leave comments, you need to log in
Is there an analogue of the choice (python) function in php?
There was a program in Python, now it needs to be transferred to PHP. PHP has just started to learn, so the question is: is there an analogue of the choice function from Python in it?
Answer the question
In order to leave comments, you need to log in
If I understand correctly:
then in PHP it is like this
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 1);
echo $input[$rand_keys[0]] . "\n";
// или
shuffle($input);
echo $input[0] . "\n";
By the way, it's useful to smoke a manual on the subject of syntax:
us2.php.net/manual/ru/function.array-rand.php
<?php
$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";
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question