嘿我正试图从json那里移动想要的数据。所以json里面的数据是从酒店预订数据,我从查询到数据库。基本上,有多个数据具有相同的日期。我只是想使用简单的else if语句将我想要的数据移动到php数组,但我无法使它工作。
这是规则: 所以'预订'比'可用'更重要。即使它仍然“可用”,如果有人“预订”它。例如,4月10日“预订”我想要的唯一数据是“4月10日预订”我不在乎它是否仍然可用。此规则也适用于“完整”。 “预订”比“完整”更重要。
这是json:
array(128) {
[0]=>
array(6) {
["start"]=>
string(16) "2016-10-03 08:00"
["end"]=>
string(16) "2016-10-03 08:30"
["id_course"]=>
string(5) "55508"
["image"]=>
string(92) "http://squline.dev/dashboard/media/images/teacher/2dd22e63084c868044b8d8840ad02e35_thumb.jpg"
["className"]=>
string(23) "custom-cursor bg-booked"
["title"]=>
string(8) "Attended"
}
[1]=>
array(5) {
["start"]=>
string(16) "2016-10-03 08:00"
["end"]=>
string(16) "2016-10-03 08:30"
["id_course"]=>
string(5) "55508"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
}
[2]=>
array(6) {
["start"]=>
string(16) "2016-10-03 08:30"
["end"]=>
string(16) "2016-10-03 09:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(23) "custom-cursor bg-booked"
["title"]=>
string(8) "Attended"
["image"]=>
string(92) "http://squline.dev/dashboard/media/images/teacher/2dd22e63084c868044b8d8840ad02e35_thumb.jpg"
}
[3]=>
array(5) {
["start"]=>
string(16) "2016-10-03 08:30"
["end"]=>
string(16) "2016-10-03 09:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
}
[4]=>
array(5) {
["start"]=>
string(16) "2016-10-03 09:00"
["end"]=>
string(16) "2016-10-03 09:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
}
[5]=>
array(5) {
["start"]=>
string(16) "2016-10-03 09:30"
["end"]=>
string(16) "2016-10-03 10:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
}
[6]=>
array(5) {
["start"]=>
string(16) "2016-10-03 10:30"
["end"]=>
string(16) "2016-10-03 11:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
}
[7]=>
array(6) {
["start"]=>
string(16) "2016-10-03 17:00"
["end"]=>
string(16) "2016-10-03 17:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[8]=>
array(6) {
["start"]=>
string(16) "2016-10-03 17:30"
["end"]=>
string(16) "2016-10-03 18:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[9]=>
array(6) {
["start"]=>
string(16) "2016-10-03 18:00"
["end"]=>
string(16) "2016-10-03 18:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[10]=>
array(6) {
["start"]=>
string(16) "2016-10-03 18:30"
["end"]=>
string(16) "2016-10-03 19:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[11]=>
array(6) {
["start"]=>
string(16) "2016-10-03 19:00"
["end"]=>
string(16) "2016-10-03 19:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[12]=>
array(6) {
["start"]=>
string(16) "2016-10-03 19:30"
["end"]=>
string(16) "2016-10-03 20:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[13]=>
array(6) {
["start"]=>
string(16) "2016-10-03 20:00"
["end"]=>
string(16) "2016-10-03 20:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[14]=>
array(6) {
["start"]=>
string(16) "2016-10-03 20:30"
["end"]=>
string(16) "2016-10-03 21:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[15]=>
array(6) {
["start"]=>
string(16) "2016-10-03 21:00"
["end"]=>
string(16) "2016-10-03 21:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[16]=>
array(6) {
["start"]=>
string(16) "2016-10-04 08:00"
["end"]=>
string(16) "2016-10-04 08:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[17]=>
array(6) {
["start"]=>
string(16) "2016-10-04 08:30"
["end"]=>
string(16) "2016-10-04 09:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[18]=>
array(6) {
["start"]=>
string(16) "2016-10-04 09:00"
["end"]=>
string(16) "2016-10-04 09:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[19]=>
array(6) {
["start"]=>
string(16) "2016-10-04 09:30"
["end"]=>
string(16) "2016-10-04 10:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[20]=>
array(6) {
["start"]=>
string(16) "2016-10-04 10:00"
["end"]=>
string(16) "2016-10-04 10:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[21]=>
array(6) {
["start"]=>
string(16) "2016-10-04 10:30"
["end"]=>
string(16) "2016-10-04 11:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[22]=>
array(6) {
["start"]=>
string(16) "2016-10-04 13:00"
["end"]=>
string(16) "2016-10-04 13:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[23]=>
array(6) {
["start"]=>
string(16) "2016-10-04 13:30"
["end"]=>
string(16) "2016-10-04 14:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[24]=>
array(6) {
["start"]=>
string(16) "2016-10-04 14:00"
["end"]=>
string(16) "2016-10-04 14:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[25]=>
array(6) {
["start"]=>
string(16) "2016-10-04 14:30"
["end"]=>
string(16) "2016-10-04 15:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[26]=>
array(6) {
["start"]=>
string(16) "2016-10-04 15:00"
["end"]=>
string(16) "2016-10-04 15:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[27]=>
array(6) {
["start"]=>
string(16) "2016-10-04 16:00"
["end"]=>
string(16) "2016-10-04 16:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[28]=>
array(6) {
["start"]=>
string(16) "2016-10-04 16:30"
["end"]=>
string(16) "2016-10-04 17:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[29]=>
array(6) {
["start"]=>
string(16) "2016-10-04 17:00"
["end"]=>
string(16) "2016-10-04 17:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[30]=>
array(6) {
["start"]=>
string(16) "2016-10-04 17:30"
["end"]=>
string(16) "2016-10-04 18:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[31]=>
array(6) {
["start"]=>
string(16) "2016-10-04 18:00"
["end"]=>
string(16) "2016-10-04 18:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[32]=>
array(6) {
["start"]=>
string(16) "2016-10-04 18:30"
["end"]=>
string(16) "2016-10-04 19:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[33]=>
array(6) {
["start"]=>
string(16) "2016-10-04 19:00"
["end"]=>
string(16) "2016-10-04 19:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[34]=>
array(6) {
["start"]=>
string(16) "2016-10-04 19:30"
["end"]=>
string(16) "2016-10-04 20:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[35]=>
array(6) {
["start"]=>
string(16) "2016-10-04 20:00"
["end"]=>
string(16) "2016-10-04 20:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[36]=>
array(6) {
["start"]=>
string(16) "2016-10-04 20:30"
["end"]=>
string(16) "2016-10-04 21:00"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[37]=>
array(6) {
["start"]=>
string(16) "2016-10-04 21:00"
["end"]=>
string(16) "2016-10-04 21:30"
["id_course"]=>
string(5) "55520"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[38]=>
array(7) {
["start"]=>
string(16) "2016-10-05 08:00"
["end"]=>
string(16) "2016-10-05 08:30"
["id_course"]=>
string(5) "55510"
["className"]=>
string(23) "custom-cursor bg-booked"
["title"]=>
string(6) "Missed"
["status"]=>
bool(false)
["image"]=>
string(92) "http://squline.dev/dashboard/media/images/teacher/2dd22e63084c868044b8d8840ad02e35_thumb.jpg"
}
[39]=>
array(6) {
["start"]=>
string(16) "2016-10-05 08:00"
["end"]=>
string(16) "2016-10-05 08:30"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[40]=>
array(6) {
["start"]=>
string(16) "2016-10-05 08:30"
["end"]=>
string(16) "2016-10-05 09:00"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[41]=>
array(6) {
["start"]=>
string(16) "2016-10-05 09:00"
["end"]=>
string(16) "2016-10-05 09:30"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[42]=>
array(6) {
["start"]=>
string(16) "2016-10-05 09:30"
["end"]=>
string(16) "2016-10-05 10:00"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[43]=>
array(6) {
["start"]=>
string(16) "2016-10-05 10:30"
["end"]=>
string(16) "2016-10-05 11:00"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[44]=>
array(6) {
["start"]=>
string(16) "2016-10-05 13:00"
["end"]=>
string(16) "2016-10-05 13:30"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[45]=>
array(6) {
["start"]=>
string(16) "2016-10-05 13:30"
["end"]=>
string(16) "2016-10-05 14:00"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[46]=>
array(6) {
["start"]=>
string(16) "2016-10-05 14:00"
["end"]=>
string(16) "2016-10-05 14:30"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[47]=>
array(6) {
["start"]=>
string(16) "2016-10-05 14:30"
["end"]=>
string(16) "2016-10-05 15:00"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[48]=>
array(6) {
["start"]=>
string(16) "2016-10-05 15:00"
["end"]=>
string(16) "2016-10-05 15:30"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-full"
["title"]=>
string(4) "Full"
["status"]=>
bool(false)
}
[49]=>
array(6) {
["start"]=>
string(16) "2016-10-05 15:30"
["end"]=>
string(16) "2016-10-05 16:00"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
[50]=>
array(6) {
["start"]=>
string(16) "2016-10-05 16:00"
["end"]=>
string(16) "2016-10-05 16:30"
["id_course"]=>
string(5) "55510"
["className"]=>
string(21) "custom-cursor bg-past"
["title"]=>
string(9) "Available"
["status"]=>
bool(false)
}
我尝试将我想要的数据移动到php数组:
foreach( $class as $key => $val )
{
if ($xcourse_date != $course_date) {
$events[] = $event;
$count_x_course_date++;
}
if( $events[$count_x_course_date - 1]['status'] != 'BOOKED' ) {
if ( $events[$count_x_course_date - 1]['status'] != 'AVAILABLE' ) {
$events[$count_x_course_date - 1] = $event;
}
}
elseif ( $events[$count_x_course_date - 1]['status'] == 'AVAILABLE' ) {
$events[$count_x_course_date - 1] = $event;
}
$xcourse_date = $val['course_date'];
$i++;
}
我的问题是: 1.我做错了什么? 2.我使用循环访问json中的所有数据,有什么方法比循环更容易? 3.我的逻辑说我的代码没有错,但结果远非我的期望,你能指出我的编程逻辑有什么问题吗?
答案 0 :(得分:1)
在数据库的数据集中
$events[$count_x_course_date - 1]['status'] == 'AVAILABLE'
哪个错误。因为从数据集中,它表示值是布尔值,即true / false
["status"] => bool(false)
。 title
字段,即["title"]=>
string(9) "Available"