我想在MySQL中使用array_diff()
命令,但我无法使其正常工作。
以下是代码:
mysqli_select_db($conection, $database);
$query_rsEvents = "SELECT * FROM events ORDER BY start ASC";
$rsEvents = mysqli_query($conection, $query_rsEvents) or die(mysqli_error());
$row_rsEvents = mysqli_fetch_assoc($rsEvents);
$array1 = range(9,23);
$array2 = array_merge(range($row_rsEvents["start"], $row_rsEvents["end"]));
foreach (array_diff($array1, $array2) as $freehours) {
echo "".$freehours."<br>";
}
我想从开始和结束记录中创建所有范围并将其合并到一个数组中
非常感谢您的帮助
答案 0 :(得分:0)
$array2 = array();
while($row_rsEvents = mysqli_fetch_assoc($rsEvents)) {
$array2 = array_merge($array2, range($row_rsEvents["start"], $row_rsEvents["end"]));
}