"PHP array rand()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
3번째 줄: 3번째 줄:
;PHP array_rand()
;PHP array_rand()


<source lang='php'>
<syntaxhighlight lang='php'>
$fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
$fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
echo $fruits[array_rand($fruits)] . "\n";
echo $fruits[array_rand($fruits)] . "\n";
9번째 줄: 9번째 줄:
echo $fruits[array_rand($fruits, 1)] . "\n";
echo $fruits[array_rand($fruits, 1)] . "\n";
# Lemon
# Lemon
</source>
</syntaxhighlight>
<source lang='php'>
<syntaxhighlight lang='php'>
$fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
$fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
$rand_keys = array_rand($fruits, 3);
$rand_keys = array_rand($fruits, 3);
25번째 줄: 25번째 줄:
# Lemon
# Lemon
# Melon
# Melon
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:57 기준 최신판

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