What does the php end method do?

青灯夜游
Release: 2023-03-12 10:14:02
Original
2470 people have browsed it

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.

What does the php end method do?

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)
Copy after login
  • 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(
    &#39;PHP中文网&#39;,
    &#39;//m.sbmmt.com/&#39;,
    &#39;PHP 教程&#39;,
    &#39;end() 函数&#39;
);
$array2 = [];
echo &#39;数组的最后一个元素是:&#39;.end($array).&#39;<br>&#39;;
var_dump(end($array2)); 
?>
Copy after login

What does the php end method do?

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(
    &#39;PHP中文网&#39;,
    &#39;//m.sbmmt.com/&#39;,
    &#39;PHP 教程&#39;,
    &#39;end() 函数&#39;
);
var_dump($array);
end($array);
$lastKey = key($array);
echo "数组最后一个键名为:".$lastKey;
?>
Copy after login

What does the php end method do?

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!