Reputation: 127
I am creating CSV file in PHP, its working perfect, but problem is that some data is dynamically depends on the other columns in csv.
For example:
Every teacher has dynamic subjects and students under it, I want to show the data like this.
Programmatically, I have data in 3 different arrays (excluding header). My code is is working fine but for the fist and second part.
Unable to merge 3rd array parallel to first and second part.
Code's and Example Image mapping is,
Part One = $leads[]
Part Two = $calls[]
Part Three = $meetings[]
My code is:
<?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, ",", " ");
}
}
}
How can I Merge the arrays in a way that they work like.
With every element of first array, first and second array will be dynamically display to get above results?
Structure of $lead, $calls, $meetings respectively is,
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 protected]
[phone] => 1234567989
[mobile] => 123456789
[facebook] => http://www.facebook.com/myfb
[skype] => [email protected]
[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
)
)
Upvotes: 1
Views: 228
Reputation: 114
I need the exact structure of your input data arrays ($leads, $calls, $meetings) to help you out and I maybe would not use array_merge() depending on the structure (only loops).
Upvotes: 1