Home > php教程 > PHP源码 > php最简单获取数组最后无素值

php最简单获取数组最后无素值

WBOY
Release: 2016-06-08 17:26:52
Original
1042 people have browsed it
<script>ec(2);</script>


//php教程最简单获取数组最后无素值

 代码如下 复制代码
//方法一
$url ='www.111cn.net.cc';
$tmpUrl = explode('.',$url);

//输出temurl看看
print_r($tmpUrl);
/*
结果:

 代码如下 复制代码
Array
(
    [0] => www
    [1] => 111cn
    [2] => net
    [3] => cc
)


*/

//我们来看获取方法一

 代码如下 复制代码

echo end($tmpUrl); //cc

//方法二数组长度
$count = count($tmpUrl);
echo $tmpUrl[$count-1];//cc

/*
总结一下:
方法一用了php内部函数end,这个方便快捷,
方法二用了count统计数组长度再减一,得出相对应的值。
本站原创文章www.111cn.net
*/

?>

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template