我在PHP中创建CSV文件,它的工作完美,但问题是某些数据动态地依赖于csv中的其他collums。
每位教师都有动态科目和学生, 我想显示这样的数据,
以编程方式,我有3个不同数组(不包括标题)的数据。 我的代码工作正常,但第一和第二部分。 无法将第三个数组并行合并到第一个和第二个部分。
代码&示例图像映射是,
Part One = $leads[]
Part Two = $calls[]
Part Three = $meetings[]
我的代码是,
<?php if (count($leads)) {
foreach ($leads as $k) {
//merging lead with every call
foreach($calls as $key => $t){
$merg[$key] = array_merge($k, $t);
}
foreach($merg as $entry){
fputcsv($file, $entry, ",", " ");
}
}
}
如何以他们工作的方式合并数组, 对于第一个数组的每个元素,将动态显示第一个和第二个数组以获得上述结果吗?
$ lead,$ calls,$ meetings的结构分别是
Array
(
[0] => Array
(
[leads_id] => 226740
[created_date] => 2018-06-06 00:00:00
[lead_name] => My Lead
[organization] => Orgnization
[address] => Street No.05
[contact_name] => Contact Name
[email] => Email@email.com
[phone] => 1234567989
[mobile] => 123456789
[facebook] => http://www.facebook.com/myfb
[skype] => Skype@skype.com
[twitter] => http://www.twitter.com/abc
[lead_desc] => This is Short Note.
[status] => Open
)
)
------------------------
Array
(
[0] => Array
(
[calls_id] => 79
[date] => 0000-00-00
[time] => 01:10PM
[call_summary] => This is Summary of the call
)
[1] => Array
(
[calls_id] => 80
[date] => 0000-00-00
[time] => 03:15PM
[call_summary] => This is Summary of the call2
)
[2] => Array
(
[calls_id] => 81
[date] => 0000-00-00
[time] => 01:05PM
[call_summary] => This is Summary of the call3
)
)
-------------------
Array
(
[0] => Array
(
[mettings_id] => 36
[meeting_subject] => Gujranwala
[start_date] => 0000-00-00
[end_date] => 0000-00-00
[start_time] => 02:10PM
[end_time] => 01:00PM
[location] => SIalkot
[description] => Hello World
)
[1] => Array
(
[mettings_id] => 37
[meeting_subject] => Introduction
[start_date] => 0000-00-00
[end_date] => 0000-00-00
[start_time] => 11:55PM
[end_time] => 03:15PM
[location] => Lahore
[description] => this is description
)
)
答案 0 :(得分:1)
我需要输入数据数组的确切结构($ leads,$ calls,$ meetings)来帮助你,我可能不会使用array_merge(),具体取决于结构(只有循环)。