LoginSignup
4
4

More than 5 years have passed since last update.

配列からランダムにn個の値を取得

Posted at

array_rand($array, n);

$myArr = array('A', 'B', 'C', 'D');
$num = array_rand($myArr, 1);
$numArr = array_rand($myArr, 2);

echo $num; // 3
echo $numArr[0]; // 2
echo $numArr[1]; // 3

echo $myArr[num]; // D
echo $myArr[numArr[0]]; // A
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4