我有PHP关联数组,如下所示,mysql查询和文件名作为键和值:
$extract_queries = array(
"SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '07:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '07:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" => $current_user."-WinterNightTime1",
"SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '07:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '07:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" => $current_user."-SummerNightTime1",
"SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '16:00:00' AND TIME(time_stamp) <= '16:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '16:00:00' AND TIME(time_stamp) <= '16:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" => $current_user."-WinterDayTime1",
"SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '18:00:00' AND TIME(time_stamp) <= '18:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '18:00:00' AND TIME(time_stamp) <= '18:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" => $current_user."-WinterPeakTime",
"SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '22:00:00' AND TIME(time_stamp) <= '22:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '22:00:00' AND TIME(time_stamp) <= '22:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" => $current_user."-WinterDayTime2",
"SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '22:00:00' AND TIME(time_stamp) <= '22:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '22:00:00' AND TIME(time_stamp) <= '22:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" => $current_user."-SummerDayTime",
"SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" => $current_user."-WinterNightTime2",
"SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" => $current_user."-SummerNightTime2"
);
我的问题是当我print_r($ extract_queries); 数组中缺少第1和第5个键及其值,即使在foreach循环中,它们也会被转义。
我如何获得这些价值?
答案 0 :(得分:3)
主键在第1和第5个重复(日期/时间相同)。将SQL查询切换为值,将$current_user."-xxxTime1"
部分切换为键
$extract_queries = array( $current_user."-WinterNightTime1" => "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '07:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '07:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate" =>
,$current_user."-SummerNightTime1" => "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '07:00:00' AND TIME(time_stamp) <= '07:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '07:00:00' AND TIME(time_stamp) <= '07:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate"
,$current_user."-WinterDayTime1" => "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '16:00:00' AND TIME(time_stamp) <= '16:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '16:00:00' AND TIME(time_stamp) <= '16:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate"
,$current_user."-WinterPeakTime" => "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '18:00:00' AND TIME(time_stamp) <= '18:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '18:00:00' AND TIME(time_stamp) <= '18:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate"
,$current_user."-WinterDayTime2" => "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '22:00:00' AND TIME(time_stamp) <= '22:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '22:00:00' AND TIME(time_stamp) <= '22:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate"
,$current_user."-SummerDayTime" => "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '22:00:00' AND TIME(time_stamp) <= '22:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '22:00:00' AND TIME(time_stamp) <= '22:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate"
,$current_user."-WinterNightTime2" => "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate"
,$current_user."-SummerNightTime2" => "SELECT rec.time_stamp, rec.day_chan1, rec.day_chan2, rec.day_chan3 FROM ( SELECT ".$this->table_name.".*, DATE(time_stamp) AS mydate, TIME(time_stamp) AS mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:59') as rec JOIN ( SELECT DATE(time_stamp) as mydate, MAX(TIME(time_stamp)) as mytime FROM ".$this->table_name." WHERE TIME(time_stamp) >= '23:00:00' AND TIME(time_stamp) <= '23:59:59' GROUP BY DATE(time_stamp) ) as max_times ON max_times.mydate = rec.mydate and max_times.mytime = rec.mytime ORDER BY rec.mydate"
);