end() - 将数组的内部指针指向最后一个单元 - php 数组函数
end()
(PHP 4, PHP 5, PHP 7)
将数组的内部指针指向最后一个单元
说明
end(array &$array): mixedend()将$array的内部指针移动到最后一个单元并返回其值。
参数
$array这个数组。该数组是通过引用传递的,因为它会被这个函数修改。这意味着你必须传入一个真正的变量,而不是函数返回的数组,因为只有真正的变量才能以引用传递。
返回值
返回最后一个元素的值,或者如果是空数组则返回FALSE
。
范例
Example #1end()例子
参见
current()
返回数组中的当前单元each()
返回数组中当前的键/值对并将数组指针向前移动一步prev()
将数组的内部指针倒回一位reset()
将数组的内部指针指向第一个单元next()
将数组中的内部指针向前移动一位
It's interesting to note that when creating an array with numeric keys in no particular order, end() will still only return the value that was the last one to be created. So, if you have something like this: This will print "0".
If you need to get a reference on the first or last element of an array, use these functions because reset() and end() only return you a copy that you cannot dereference directly:
This function returns the value at the end of the array, but you may sometimes be interested in the key at the end of the array, particularly when working with non integer indexed arrays: Usage example:
Attempting to get the value of a key from an empty array through end() will result in NULL instead of throwing an error or warning becuse end() on an empty array results in false: Results in: string(2) "c1" NULL NULL
If all you want is the last item of the array without affecting the internal array pointer just do the following: This works because the parameter to the function is being sent as a copy, not as a reference to the original variable.
I found that the function end() is the best for finding extensions on file name. This function cleans backslashes and takes the extension of a file.
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)