我目前正在尝试在PHP中按截止日期对多维数组进行排序,但排序不成功。我已尝试在这里应用几种解决方案,但没有运气。有人可以就下面代码的正确解决方案提出建议吗?
function getTasksTeam($user) {
$master = array();
$master["record"] = array();
$teamArray = array();
$teams = mysql_query("SELECT * FROM users WHERE _id = '$user'") or die(mysql_error());
if (mysql_num_rows($teams) > 0) {
while(($row = mysql_fetch_assoc($teams))) {
$teamArray = explode(':', $row["TEAM"]);
}
}
for ($i = 0;$i < count($teamArray);$i++) {
$teamId = $teamArray[$i];
$query = mysql_query("SELECT * FROM tasks WHERE RESPONSIBLE_TYPE = '0' AND RESPONSIBLE = '$teamId' AND STATUS <> 3") or die(mysql_error());
if (mysql_num_rows($query) > 0) {
while (($row = mysql_fetch_assoc($query))) {
$record = array();
$record["id"] = $row["_id"];
$record["task"] = $row["TASK"];
$record["part_number"] = $row["PART_NUMBER"];
$record["due"] = $row["DATE_DUE"];
$record["responsible"] = $row["RESPONSIBLE"];
$record["status"] = $row["STATUS"];
array_push($master["record"], $record);
}
}
}
usort($master["record"], 'date_sort');
$master["success"] = 1;
header('Content-type: application/json');
echo json_encode($master);
}
function date_sort($a, $b) {
return strcmp($a['due'], $b['due']);
}