Szabi Szabi Szabi Szabi - 18 days ago 6
PHP Question

Select keys where value is empty /array/php

I have array,where is a lot of empty field. How can I remove the filled fields,and make new array with the empty fields.
So,example:

[0] => Array
(
[id] => 26
[user_type] => 2
[user_name] => Julian
[password] => b941da1629f4742de62796d51730edbb
[fpassword] => 1
[email] => akombakom@abrakadabra.dabra
[name] =>
[surname] =>
[birthday] => 0000-00-00
[country] =>
[city] =>
[adress] =>
[post_code] =>
[mob_number] => 77077412
[tel_number] => 0
[web_page] =>
[registration_date] => 2016-11-19 05:03:05
[active] => 1
[activation_code] => 714779
[last_login] => 2016-11-20 12:06:36
)


So I want this:

[0] => Array
(
[name] =>
[surname] =>
[birthday] => 0000-00-00
[country] =>
[city] =>
[adress] =>
[post_code] =>
[tel_number] => 0
[web_page] =>

)


I tired
array_diff($data, array(''));
,but nothing happend.Thx

Answer

You can do something like this, in $a1 - just keep rules which values you want to see in new array.

$a1 = array('empty' => '', 'another_rule' => '0000-00-00');
$a2 = array(
            'id' => 26,
            'user_type' => 2,
            'name' => '',
            'birthday' => '0000-00-00',
        );
$result = array_intersect($a2, $a1);