PHP array_rand()

Jmnote (토론 | 기여)님의 2018년 6월 17일 (일) 18:33 판 (→‎같이 보기)

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 }}