I have the next foreach:
foreach(json_decode($result[$k], "true") as $result) {
fputcsv($fp, $result);
}
and if I put a var_dump of that result it will return a list of arrays like:
["Id"]=> string(7) "1"
["Name"]=> string(29) "Name"
["Description"]=> string(19) "Description"
["Address"]=> string(27) "Address"
["Schedule"]=> array(7) {
[0]=> array(2) {
["startHour"]=> string(5) "00:00"
["stopHour"]=> string(5) "23:59"
}
[1]=> array(2) {
["startHour"]=> string(5) "00:00"
["stopHour"]=> string(5) "23:59"
}
[2]=> array(2) {
["startHour"]=> string(5) "00:00"
["stopHour"]=> string(5) "23:59"
}
. . .
}
If I put fputcsv($fp, $result)
in that foreach loop, everything works good until Schedule. The line from csv looks like:
1, Name, Description, Address, Array.
But, what I want instead of "Array" I want something like
00:00-23:59.
Like:
1, Name, Description, Address, 00:00-23:59, 00:00-23:59, 00:00-23:59
(for each day of the week). Can anyone help me with this? Thank you!
3
Answers
You can do this in your
foreach
, if you have always set up 7 schedule entriesNote: You should give the foreach variable another name e.g.
$item
, because you are using a variable named$result
injson_decode
You will need to process the 2 arrays seperately.
I had to fake up some data as an array so I missed out the json conversion part of your code
RESULTS