【发布时间】:2015-09-04 08:04:38
【问题描述】:
我有以下数组
$array = [
'top' => [
'under' => [
'emails' =>
[
'test@email.com' => [
'key' => 'value',
],
'other' => [
'key' => 'value',
]
],
],
],
];
然后我执行以下命令
$tmp = Hash::check($array, 'top.under.emails.test@email.com');
这会返回false
如果我将电子邮件值更改为 test,然后执行以下行:
$tmp = Hash::check($array, 'top.under.emails.test');
它返回true。所以我猜这是一个问题,因为@ 字符......有没有办法解决这个问题?
总结:
$tmp = Hash::check($array, 'top.under.emails.other');
var_dump($tmp); //true
$tmp = Hash::check($array, 'top.under.emails.[test@email.com]');
var_dump($tmp); //false
$tmp = Hash::check($array, 'top.under.emails.test@email.com');
var_dump($tmp); //false
$tmp = Hash::check($array, 'top.under.emails.test@email.com.key');
var_dump($tmp); //false
【问题讨论】:
-
您不需要字符串指示符,即
$tmp = Hash::check($array, '{s}.top.under.emails.test@email.com'); -
不,我没有。如果我这样做了,那么这个
$tmp = Hash::check($array, 'top.under.emails.test');将不会返回true。 -
你试过
$tmp = Hash::check($array, 'top.under.emails.test@email.com.key');吗? -
首先,如果密钥不存在而电子邮件存在怎么办?我不想检查密钥是否存在。我想检查电子邮件地址是否存在。无论如何它都会返回
false。
标签: php arrays cakephp multidimensional-array cakephp-3.0