閲覧数:280
投稿日:2023-11-22
更新日:2023-11-22
配列内よりランダムに要素(例えば画像URL)を取得
コード
$imgAry='https://hoge1.jpg','https://hoge2.jpg','https://hoge3.jpg','https://hoge4.jpg']; print_r(count($imgAry)); //4 $randomKey = random_int(0, count($imgAry)-1); print_r($imgAry[$randomKey]);
結果
'https://hoge2.jpg