PHP berikutnya () function
contoh
Output array saat elemen dan elemen berikutnya nilai:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people);
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people);
?>
Menjalankan contoh »
Definisi dan Penggunaan
berikutnya () fungsi dalam pointer internal untuk elemen berikutnya dalam array, dan output.
metode terkait:
- yang PREV () - pointer internal untuk elemen terakhir dari array, dan output.
- Saat ini () - Mengembalikan nilai elemen saat dalam array.
- End () - pointer internal untuk elemen terakhir dalam array, dan output.
- RESET () - pointer internal untuk elemen pertama dalam array, dan output.
- setiap () - Mengembalikan nama kunci elemen saat ini dan nilai-nilai, dan pointer internal yang bergerak maju.
tatabahasa
next( array )
参数 | 描述 |
---|---|
array | 必需。规定要使用的数组。 |
rincian teknis
Pengembalian: | Jika berhasil, nilai kembali dari elemen array berikutnya, jika tidak lebih dari elemen array mengembalikan FALSE. |
---|---|
Versi PHP: | 4+ |
contoh yang lebih
contoh 1
Semua metode presentasi yang relevan:
<?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
?>
$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
?>
Menjalankan contoh »
Lengkap PHP Array Referensi