PHP next()ฟังก์ชั่น
ตัวอย่าง
ส่งออกค่าขององค์ประกอบปัจจุบันและถัดไปในอาร์เรย์:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people);
?>
ความหมายและการใช้งาน
ฟังก์ชัน next() จะย้ายตัวชี้ภายในไปยังและส่งออกองค์ประกอบถัดไปในอาร์เรย์
วิธีการที่เกี่ยวข้อง:
- prev() - ย้ายตัวชี้ภายในไปยังและส่งออกองค์ประกอบก่อนหน้าในอาร์เรย์
- ปัจจุบัน () - ส่งกลับค่าขององค์ประกอบปัจจุบันในอาร์เรย์
- end() - ย้ายตัวชี้ภายในไปยังและส่งออกองค์ประกอบสุดท้ายในอาร์เรย์
- reset() - ย้ายตัวชี้ภายในไปยังองค์ประกอบแรกของอาร์เรย์
- each() - คืนค่าคีย์องค์ประกอบปัจจุบันและย้ายตัวชี้ภายในไปข้างหน้า
ไวยากรณ์
next(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