I have data that’s setup the following way:
array(
0 => array(
'data_id' => 0,
'elem_value' => 'phone',
'elem_prettyname' => 'Phone Number'
),
1 => array(
'data_id' => 0,
'elem_value' => 'email',
'elem_prettyname' => 'Email Address'
),
2 => array(
'data_id' => 1,
'elem_value' => 'phone',
'elem_prettyname' => 'Phone Number'
),
3 => array(
'data_id' => 1,
'elem_value' => 'email',
'elem_prettyname' => 'Email Address'
)
)
)
I’m trying to turn that into a csv file that looks like:
"Data ID","Phone Number","Email Address"
0,"phone","email"
1,"phone","email"
But I can’t figure it out for the life of me. I have tons of random arrays and they go nowhere.
I should mention that the elem_prettyname can have an infinite number of elements.. IE not just Phone Number and Email Address.
Can anyone point me in the right direction to get that formatted correctly?
Thanks in advance.
you need to convert your data to an array that looks like this:
0,"phone","email"first.Something like this:
If that’s the format you want (which isn’t clear from the question) – you then simply dump the data into a file with
fputcsvor, simply, with fwrite.