PHP | end() Function
The end() function is an inbuilt function in PHP and is used to find the last element of the given array. The end() function changes the internal pointer of an array to point to the last element and returns the value of the last element.
Syntax:
end($array)
Parameters: This function accepts a single parameter $array. It is the array of which the last element we want to find.
Return Value: It returns the value of the last element of the array on success but FALSE on failure i.e, when the array is empty.
Examples:
Input: array('Ram', 'Shita', 'Geeta')
Output: Geeta
Explanation: Here input array contain many
elements but output is Geeta i.e, last element
of the array as the end() function returns the
last element of an array.
Below programs illustrate the end() function in PHP:
Program 1:
<?php // input array $arr = array('Ram', 'Shita', 'Geeta'); // end function print the last // element of the array. echo end($arr); ?> |
Output:
Geeta
Program 2:
<?php // input array $arr = array('1', '3', 'P'); // end function print the last // element of the array. echo end($arr)."\n"; // end() updates the internal pointer // to point to last element as the // current() function will now also // return last element echo current($arr); ?> |
Output:
P P
Reference:
http://php.net/manual/en/function.end.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- CSS | rgb() Function
- PHP | Ds\Set last() Function
- PHP | Ds\Set first() Function
- PHP | Ds\Set add() Function
- PHP Ds\Set sum() Function
- PHP | Ds\Map xor() Function
- CSS | var() Function
- D3.js | d3.mean() function
- PHP | tan( ) Function
- CSS | hsl() Function
- p5.js | sq() function
- D3.js | d3.sum() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



