使用变量操作多维数组

时间:2013-05-20 13:18:01

标签: php

我想使用变量的值并将其分配给数组。

例如 - 此代码有效:

$mf_hook_emails[19734]['Dept Notify'] = 'customer_service@abc.com';

但是这段代码不起作用(首先将电子邮件地址分配给变量):

$deptemail='customer_service@abc.com';
$mf_hook_emails[19734]['Dept Notify'] = $deptemail;                        

2 个答案:

答案 0 :(得分:1)

$deptemail='customer_service@abc.com';
$mf_hook_emails[19734]['Dept Notify'] = $deptemail;  

这对我来说很好。 print_r($mf_hook_emails)给出:

Array (
       [19734] => Array (
             [Dept Notify] => customer_service@abc.com
             )
      )

答案 1 :(得分:0)

您可以这样定义: -

 $mf_hook_emails[19734]['Dept Notify'] = (string)$deptemail;