함수 get_random_element()

함수 get_random_element()
함수 get_random_item()

1 JavaScript[ | ]

var fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
console.log( fruits [Math.floor(Math.random()*fruits .length)] );
// Banana

2 PHP[ | ]

$fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
echo $fruits[array_rand($fruits)];
# Lemon
function get_random_element($arr) { return $arr[array_rand($arr)]; }
$fruits = ['Apple', 'Banana', 'Lemon', 'Melon'];
var_dump( get_random_element($fruits) );
var_dump( get_random_element($fruits) );
var_dump( get_random_element($fruits) );
# string(5) "Apple"
# string(5) "Melon"
# string(5) "Apple"

3 같이 보기[ | ]

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