for循环应该循环10次。
当我打印$fname$lname$email
我得到10个数据(工作正常)
但我需要将这些值存储在关联数组中。

$assocDataArray = array();
foreach ($data as $key => $value) {
    foreach ($value['emails'] as $lead) {
        $fname = $lead['first_name'];
        $lname = $lead['last_name'];
        $email = $lead['value'];

        //put objects in array
        $assocDataArray += [ "First Name" => $fname ];
        $assocDataArray += [ "Last Name" => $lname ];
        $assocDataArray += [ "Email" => $email ];
    }
}

var_dump($assocDataArray);

var_dump只给了我一个数组[应该是10]

最佳答案

本次派遣:

$assocDataArray += [ "First Name" => $fname ];
$assocDataArray += [ "Last Name" => $lname ];
$assocDataArray += [ "Email" => $email ];

是错误的。改成下面这样
$assocDataArray[] = [ "First Name" => $fname ,"Last Name" => $lname ,"Email" => $email ];

07-24 19:09