by shigemk2

当面は技術的なことしか書かない

array_rand メモ

  • 8.0.0 Argument #2 ($num) must be between 1 and the number of elements in argument #1 ($array)
  • 7.4.0 Second argument has to be between 1 and the number of elements in the array
  • 7.3.0 Second argument has to be between 1 and the number of elements in the array
<?php
var_dump(array_rand([1,2,3], 4));
var_dump(array_rand([1,2,3], 2));

array_randの第2匹数が配列の要素数より多かったら出るエラー。 エラー内容はバージョンによって違うけど、エラーの条件は一緒だしエラーは出すし何も返してこない。