PHP | next() Function
The next() function is an inbuilt function in PHP and does the following operations:
- It is used to return the value of the next element in an array which the internal pointer is currently pointing to. We can know the current element by current function.
- The next() function increments the internal pointer after returning the value.
- In PHP, all arrays have an internal pointer. This internal pointer points to some element in that array which is called as the current element of the array.
- Usually, the next element at the beginning is the second inserted element in the array.
Parameter: It accepts only one parameter $array. This parameter is mandatory. It is the array in which we need to find the next element.
Return Value: The function returns the value of the next element in an array of which the internal pointer is currently pointing to. It returns FALSE if there is no element at next. Initially the next() function returns the second inserted element.
Input : array = [1, 2, 3, 4] Output : 2 Input : array = [1, 2, 3, 4], next() function executed two times Output : 2 3
Below programs illustrate the next() function in PHP:
geeks Raj Raj striver striver coding coding