[ create a new paste ] login | about

Link: http://codepad.org/GmvO94SI    [ raw code | output | fork ]

PHP, pasted on Jan 30:
<?php

$user = array(
    'id' => 1,
    'username' => 'hank',
    'password' => 'c9f3fa9ff1cc03389b960f877e9c909e6485ag6h',
    'email' => 'user_email@hotmail.com',
    'country' => '',
    'city' => '',
    'phone' => '666666666',
    'other' => '',
);

$fields = array('country', 'city', 'phone');
$check = array_filter(array_intersect_key($user, array_flip($fields)));

var_dump($check);

if (count($check) !== count($fields)) {
    // Bad; some fields are empty
    echo 'Bad';
} else {
    // OK
    echo 'Good';
}


Output:
1
2
3
4
5
array(1) {
  ["phone"]=>
  string(9) "666666666"
}
Bad


Create a new paste based on this one


Comments: