1 개요[ | ]
- PHP array_rand()
PHP
Copy
$fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
echo $fruits[array_rand($fruits)] . "\n";
# Banana
echo $fruits[array_rand($fruits, 1)] . "\n";
# Lemon
PHP
Copy
$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 참고[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.