Home  >  Article  >  php教程  >  php数组过滤重置键名功能

php数组过滤重置键名功能

WBOY
WBOYOriginal
2016-06-08 17:22:171659browse

使用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

)

*/

?>

Statement:
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