次の配列 (CakePHP 配列) があります。
Array
(
[id] => 1
[username] => hank
[password] => c9f3fa9ff1cc03389b960f877e9c909e6485ag6h
[email] => user_email@hotmail.com
[country] =>
[city] =>
[phone] => 666666666
[other] =>
)
country
そして、特定のフィールドが NULL か空か (または など)を知りたいですcity
。私はこれを試しました:
私のコントローラーで:
...
$user = $this->User->findById($id);
$this->set('user', $user['User']); # $user['User'] returns the array seen before.
私からしてみれば
<?php $fields = array('country', 'city', 'phone'); ?>
<?php if (!in_array($fields, $user, true)): ?>
<p>Bad, some fields of $fields are empty</p>
<?php else: ?>
<p>Ok</p
<?php endif;?>
しかし、これはうまくいきません。のフィールドのいずれか$fields
が NULL または空かどうかを知る必要があります。