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 ];