PHP array_rand()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:57 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

PHP array_rand()
$fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
echo $fruits[array_rand($fruits)] . "\n";
# Banana
echo $fruits[array_rand($fruits, 1)] . "\n";
# Lemon
$fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
$rand_keys = array_rand($fruits, 3);
# Array
# (
#     [0] => 0
#     [1] => 2
#     [2] => 3
# )
echo $fruits[$rand_keys[0]] . "\n";
echo $fruits[$rand_keys[1]] . "\n";
echo $fruits[$rand_keys[2]] . "\n";
# Apple
# Lemon
# Melon

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}