Php prev
From w3cyberlearnings
Contents |
PHP function prev
This function points to the previous array element. If there are no more elements, it returns FALSE.
Syntax prev
- array: array input
prev(array);
Example 1
<?php $array = array( 'Semester 1', 'Semester 2', 'Semester 3', 'Semester 4', 'Semester 5', 'Semester 6', 'Semester 7', 'Semester 8' ); // by default, the pointer is on the first element semester 1 echo current($array) . "<br />"; // "semester 1" // skip two semesters next($array); // next($array); // echo current($array) . "<br/>"; // semester 3 echo prev($array) . "<br/>"; // semester 2 // skip three semesters next($array); // next($array); // next($array); // echo current($array) . "<br />"; // "semester 5" echo prev($array) . "<br/>"; // semester 4 // reset pointer, start again on semester 1 reset($array); echo current($array) . "<br />"; // "semester 1" ?>
Output
Semester 1 Semester 3 Semester 2 Semester 5 Semester 4 Semester 1
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys