2015-09-04 27 views
1

我有以下阵列哈希::检查方法不能在电子邮件键返回true

$array = [ 
    'top' => [ 
     'under' => [ 
      'emails' => 
       [ 
        '[email protected]' => [ 
         'key' => 'value', 
        ], 
        'other' => [ 
         'key' => 'value', 
        ] 
       ], 
     ], 
    ], 
]; 

然后我执行以下命令

$tmp = Hash::check($array, '[email protected]'); 

这将返回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.[[email protected]]'); 
var_dump($tmp); //false 
$tmp = Hash::check($array, '[email protected]'); 
var_dump($tmp); //false 
$tmp = Hash::check($array, '[email protected]'); 
var_dump($tmp); //false 
+0

不要你需要即'$ TMP =哈希::检查字符串指标($数组,'{s}[email protected]');' – RiggsFolly

+0

不,我不知道。如果我做了,那么''tmp = Hash :: check($ array,'top.under.emails.test');''不会返回'true''。 – gmponos

+0

你试过'$ tmp = Hash :: check($ array,'[email protected]');'? – aldrin27

回答

1

周围使用电子邮件键方括号匹配特定的键: -

Hash::check($array, 'top.under.emails[[email protected]]'); 
+0

不,它不起作用 – gmponos

+0

奇怪的是,这对我的数组适用。 – drmonkeyninja

+0

哦,你不是放点。这就是为什么......让我测试它。 – gmponos