【发布时间】:2018-04-07 20:06:58
【问题描述】:
我想要实现的是:
开放时间:
0:
1:
2:
等等
我实际拥有的是:
{
"message": {
"entity": {
"google_places": [
{
"opening_times": [
"Monday: 11:30 AM – 8:30 PM"
]
},
{
"opening_times": [
"Tuesday: 11:30 AM – 8:30 PM"
]
},
{
"time": "3 weeks ago",
"author_name": "Adam Walsh",
"rating": 4
}
]
}
}
}
我的代码是:
if (!empty($dirty_googlePlaces_array['result']['opening_hours']['weekday_text'])) {
foreach ($dirty_googlePlaces_array['result']['opening_hours']['weekday_text'] as $opening) {
$googlePlaces_array[] = ['opening_times' => [ $opening]];
}
}
if (!empty($dirty_googlePlaces_array['result']['reviews'])) {
foreach ($dirty_googlePlaces_array['result']['reviews'] as $review) {
$author_name = $review['author_name'];
$time = $review['relative_time_description'];
$rating = $review['rating'];
}
}
$googlePlaces_array[] = [
'time' => $time,
'author_name' => $author_name,
'rating' => $rating,
];
return response()->json(['message' => ['entity' => [
'google_places' => $googlePlaces_array
]]], 200);
如何重新构造该格式以具有数组:
googlePlaces:
opening_times:
array here
time:time
author_name:string
rating: number
【问题讨论】:
标签: php arrays laravel laravel-5