Home > php教程 > PHP源码 > body text

php数组过滤重置键名功能

WBOY
Release: 2016-06-08 17:22:17
Original
1672 people have browsed it

使用array_filter函数可以过滤掉键值为空的元素,数组键名不变。如果想要过滤后的键名重新从0开始,可以使用array_values函数。

<script>ec(2);</script>
 代码如下 复制代码

$imgurl_str="||http://www.111cn.net|http://www.111cn.net|http://www.111cn.net";
$imgurl_arr = explode ( "|", $imgurl_str );
$imgurl_arr =array_filter($imgurl_arr);
print_r($imgurl_arr);
$imgurl_arr = array_values($imgurl_arr);
print_r($imgurl_arr);
/*

Array

(

    
[2] => http://www.111cn.net

    
[3] => http://www.111cn.net

    
[4] => http://www.111cn.net

)

Array

(

    
[0] => http://www.111cn.net

    
[1] => http://www.111cn.net

    
[2] => http://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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!