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

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

WBOY
Release: 2016-06-06 20:47:28
Original
976 people have browsed it

<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">
Copy after login
Copy after login
'; 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">
Copy after login
Copy after login
'; 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

Related labels:
php
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template