Home > php教程 > PHP源码 > php 去除数组空值

php 去除数组空值

WBOY
Release: 2016-06-08 17:29:41
Original
1047 people have browsed it

php 去除数组空值

<script>ec(2);</script>


我们要使用教程中经常会看到关于如何去除php数据中的空值了,下面我们提供二种去除空值的方法
$t=",,,,中国WEB第一站,www.111cn.net"
$ar= explode(',',$t);

function filter($var)
{
 if($var == '')
 {
  return false;
 }

return true;
}

array_filter($ar, "filter");

/*
foreach( $ar as $temp=>$k)
{
 if( $k )
 {   
         unset( $ar[$k] );   
 }   

}
print_r( $ar );
*/

上面函数得出的结果为
中国WEB第一站,www.111cn.net

本站原创转载注明来自www.111cn.net/phper/php.html

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