Home >Backend Development >PHP Tutorial >如何快速的在数组中取出健值不等于null的数组元素?

如何快速的在数组中取出健值不等于null的数组元素?

WBOY
WBOYOriginal
2016-06-06 20:47:28974browse

<code>    $arr = array(
        'id'=>'5',
        'name'=>'user',
        'pwd'=>'',
        'email'=>'user@163.com',
        'acl'=>'',
        'status'=>'1',
    );
    function ifs($arr){
        foreach($arr as $k=>$v){
            return empty($v) ? null : $where;
        }
    }
    echo '<pre class="brush:php;toolbar:false">
'; print_r(ifs($arr)); /*输出如下: array( 'id'=>'5', 'name'=>'user', 'pwd'=>'', 'email'=>'user@163.com', 'acl'=>'', 'status'=>'1', ) 希望是: array( 'id'=>'5', 'name'=>'user', 'email'=>'user@163.com', 'status'=>'1', ) */

回复内容:

<code>    $arr = array(
        'id'=>'5',
        'name'=>'user',
        'pwd'=>'',
        'email'=>'user@163.com',
        'acl'=>'',
        'status'=>'1',
    );
    function ifs($arr){
        foreach($arr as $k=>$v){
            return empty($v) ? null : $where;
        }
    }
    echo '<pre class="brush:php;toolbar:false">
'; print_r(ifs($arr)); /*输出如下: array( 'id'=>'5', 'name'=>'user', 'pwd'=>'', 'email'=>'user@163.com', 'acl'=>'', 'status'=>'1', ) 希望是: array( 'id'=>'5', 'name'=>'user', 'email'=>'user@163.com', 'status'=>'1', ) */

array_filter

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