반응형
배열에서 임의 항목 가져 오기
이 질문에는 이미 답변이 있습니다.
- 배열에서 임의의 값을 얻는 방법? 답변 16 개
$items = Array(523,3452,334,31,...5346);
이 배열의 각 항목은 숫자입니다.
에서 임의의 항목을 $items
어떻게 얻 습니까?
echo $items[array_rand($items)];
다른 시간에 같은 항목을 다시 고르지 않아도되는 경우 :
$items[rand(0, count($items) - 1)];
PHP Rand 기능 사용
<?php
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "\n";
echo $input[$rand_keys[1]] . "\n";
?>
사용하다 array_rand()
PHP 매뉴얼 참조-> http://php.net/manual/en/function.array-rand.php
참고 URL : https://stackoverflow.com/questions/4233407/get-random-item-from-array
반응형
'IT story' 카테고리의 다른 글
$ location / html5와 hashbang 모드 간 전환 / 링크 재 작성 (0) | 2020.05.20 |
---|---|
중첩 된 ng-click 호출 간의 이벤트 전파를 취소하는 가장 좋은 방법은 무엇입니까? (0) | 2020.05.19 |
원격 시스템에서 Ansible 작업을 사용하여 파일을 이동 / 이름 바꾸기하는 방법 (0) | 2020.05.19 |
PHP stdClass에서 배열로 (0) | 2020.05.19 |
UILabel의 글꼴 크기를 동적으로 변경 (0) | 2020.05.19 |