一般来说,使用yii2的动态表单和多字段扩展,我将数据集存储在mysql中的json字段中,我为站点编写了一个api,我显示了所有这些东西,我格式化了数组,并尝试返回它,但是我有同样的 json 字符串,看起来像这样:
[
{
"hour": "14",
"minutes": [
{"minute": "00", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "10", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "20", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "30", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "40", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "50", "count_ticket": 1, "count_ticket_left": 1}
],
"price_stud": "1",
"price_adults": "1",
"tickets_left": "6",
"count_tickets": "6",
"price_children": "1"
}, {
"hour": "15",
"minutes": [
{"minute": "00", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "10", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "20", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "30", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "40", "count_ticket": 1, "count_ticket_left": 1},
{"minute": "50", "count_ticket": 1, "count_ticket_left": 1}
],
"price_stud": "1",
"price_adults": "1",
"tickets_left": "6",
"count_tickets": "6",
"price_children": "1"
}
]
一般来说,什么可以更简单,但由于某种原因,我被困在这一点上,我正试图像这样获得这个奇迹:
foreach ($scheduleTickets as $ticket) {
$new_date_ticket = new DateTime($ticket['date']);
$norm_date = $new_date_ticket->format('d.m.Y');
if ((int)$ticket['status'] == Tickets::STATUS_ON) {
$allowTickets[$norm_date] = [];
$allowTickets[$norm_date]['tickets'] = (int)$ticket['tickets_left'];
$allowTickets[$norm_date]['hours'] = [];
if ((int)$ticket['tickets_left'] > 0) {
$i = 0;
Yii::info($ticket);
Yii::info($ticket['schedule_minute']);
foreach ($ticket['schedule_minute'] as $time_hour) {
Yii::info($time_hour);
$allowTickets[$norm_date]['hours'][$i]['value'] = (int)$time_hour->hour;
$allowTickets[$norm_date]['hours'][$i]['label'] = (string)$time_hour->hour;
$allowTickets[$norm_date]['hours'][$i]['tickets'] = $time_hour->tickets_left;
$allowTickets[$norm_date]['hours'][$i]['price_children'] = $time_hour->price_children;
$allowTickets[$norm_date]['hours'][$i]['price_stud'] = $time_hour->price_stud;
$allowTickets[$norm_date]['hours'][$i]['price_adults'] = $time_hour->price_adults;
$allowTickets[$norm_date]['hours'][$i]['minutes'] = [];
if ((int)$time_hour->tickets_left > 0) {
$y = 0;
foreach ($time_hour['minutes'] as $time_minute) {
$allowTickets[$norm_date]['hours'][$i]['minutes'][$y]['value'] = (int)$time_minute->minute;
$allowTickets[$norm_date]['hours'][$i]['minutes'][$y]['label'] = (string)$time_minute->minute;
$allowTickets[$norm_date]['hours'][$i]['minutes'][$y]['tickets'] = $time_minute->count_ticket_left;
$y++;
}
}
$i++;
}
}
}
}
一般来说,我需要你的帮助,如何访问这些数据?
我发现了一个错误,一切都很简单,总的来说,这是工作代码: