PHP 현재() 함수
예시
배열의 현재 요소 값을 출력합니다.
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
?>
정의 및 사용
current() 함수는 배열의 현재 요소 값을 반환합니다.
모든 배열에는 배열에 삽입된 첫 번째 요소로 초기화되는 "현재" 요소에 대한 내부 포인터가 있습니다.
팁: 이 함수는 배열 내부 포인터를 이동하지 않습니다.
관련 방법:
- end() - 내부 포인터를 배열의 마지막 요소로 이동하고 출력합니다.
- next() - 내부 포인터를 배열의 다음 요소로 이동하고 출력합니다.
- prev() - 내부 포인터를 배열의 이전 요소로 이동하고 출력합니다.
- reset() - 내부 포인터를 배열의 첫 번째 요소로 이동합니다.
- each() - 현재 요소 키와 값을 반환하고 내부 포인터를 앞으로 이동합니다.
통사론
current(array)
매개변수 값
Parameter | Description |
---|---|
array | Required. Specifies the array to use |
기술적 세부 사항
반환 값: | 배열에 있는 현재 요소의 값을 반환하거나 빈 요소나 값이 없는 요소에 대해서는 FALSE를 반환합니다. |
---|---|
PHP 버전: | 4+ |
더 많은 예
예시
모든 관련 방법의 데모:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
?>
❮ PHP 배열 참조