Home >Backend Development >PHP Problem >What does the php end method do?
php The function of the end method is to point the internal pointer of the array to the last element of the array and return the key value of the last element. Its usage syntax is "end($array)"; it can also be used After end() points the pointer to the last element, use "key($array)" to get the key name of the last element.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
What is the php end method for?
In PHP, the end() function can point the internal pointer of the array to the last element of the array (at this time) and return the value of the last element. If the array is empty, it returns FALSE.
The syntax format of the end() function is as follows:
end($array)
The parameter $array is the array to be operated on.
Return value: If successful, return the value of the last element in the array, if the array is empty, return FALSE.
Example:
<?php header("Content-type:text/html;charset=utf-8"); $array = array( 'PHP中文网', '//m.sbmmt.com/', 'PHP 教程', 'end() 函数' ); $array2 = []; echo '数组的最后一个元素是:'.end($array).'<br>'; var_dump(end($array2)); ?>
Using the end() function and key() function, you can also get the key name of the last element of the array. The
end() function will point the internal pointer of the array to the last element (at this time the last element is the current element of the array); then use the key() function to obtain the key name of the current element.
<?php header("Content-type:text/html;charset=utf-8"); $array = array( 'PHP中文网', '//m.sbmmt.com/', 'PHP 教程', 'end() 函数' ); var_dump($array); end($array); $lastKey = key($array); echo "数组最后一个键名为:".$lastKey; ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What does the php end method do?. For more information, please follow other related articles on the PHP Chinese website!