php - CSV 文件中的动态内容
问题描述
我在 PHP 中创建 CSV 文件,它的工作很完美,但问题是某些数据是动态依赖于 csv 中的其他列的。
例如:
每个老师都有动态的科目和学生,我想这样显示数据。
以编程方式,我有 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
)
)
解决方案
我需要您的输入数据数组($leads、$calls、$meetings)的确切结构来帮助您,我可能不会使用 array_merge(),具体取决于结构(仅循环)。
推荐阅读
- python - 怎么了?初始化模块“pyperclip”没有属性“粘贴”(很可能是由于循环导入)
- pcap - 如何在合并到单个文件之前为众多 pcap 文件中的所有数据包添加注释
- azure - 当我的应用服务在 Azure 上收到错误 500 时向我发送电子邮件
- android - 在 Android Studio 中将图标添加到工具栏
- php - 当新用户未出现在 phpmyadmin 数据库中时,php 中的注册过程成功完成
- regex - 带变量的 awk 处理
- php - json没有被php接收
- javascript - React-snapshot 使用 create-react-app 和 serve 在所有路由上预渲染 index.html
- powershell - 如何使用 powershell 更改任务触发器?
- c - Atmel:中断后无法转主