Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน next() ใน PHP

คำอธิบาย

ฟังก์ชัน next() ย้าย internal pointer ของอาร์เรย์ไปยังสมาชิกถัดไป และคืนค่าของสมาชิกนั้น

รูปแบบการใช้งาน (Syntax)

next(array)

พารามิเตอร์

  • array — อาร์เรย์ที่ต้องการใช้งาน

ค่าที่คืนกลับ

คืนค่าของสมาชิกถัดไป หรือ FALSE หากไม่มีสมาชิกถัดไป

ตัวอย่างการใช้งาน

<?php
$os = array('windows', 'mac', 'linux', 'solaris');
echo current($os) . "<br>"; // windows
echo next($os);              // mac
?>

ผลลัพธ์

windows
mac

ตัวอย่างเพิ่มเติม

<?php
$a = array('one', 'two', 'three', 'four', 'five', 'six');
echo current($a) . "\n"; // one
echo next($a) . "\n";    // two
echo current($a) . "\n"; // two (current ยังอยู่ที่ two)
echo next($a) . "\n";    // three
echo end($a) . "\n";     // six (กระโดดไปตัวสุดท้าย)
echo current($a) . "\n"; // six
?>

ผลลัพธ์

one
two
two
three
six
six