現在先假設是取了一堆date的陣列 格式為"YY-MM-DD" $dateQuery = "select date from `healthrecord_testresult_sleep` where `uid`=".$uid." ORDER BY `rid` DESC"; $date = mysql_query($query) or die('Query failed : ' . mysql_error()); $allDate = array(); while($dateArray = mysql_fetch_assoc($date)) { $allDate[] = $dateArray['date']; } $dateYear = array(); $dateMonth = array(); $dateDay = array(); // 怕會把重複的value加到年、月、日的array中,故以in_array()去過濾 foreach($allDate as $value) { list($year, $month, $day) = split('[/.-]', $value); if(!in_array($year, $dateYear)) { $dateYear["$year"] = $year; } if(!in_array($month, $dateMonth)) ...