|
|
|
รบกวนถามการจัดกลุ่มช่วงเวลาค่ะ เช่น 09.00-15.00 และ 11.00-20.00 ให้รวมกันและแสดงเป็น 09.00-20.00 |
|
|
|
|
|
|
|
น่าจะประมาณนี้ครับ
Code (PHP)
<?php
$times = array(
array(
"start" => 1100,
"end" => 1400
),
array(
"start" => 1300,
"end" => 1700
),
array(
"start" => 1900,
"end" => 1200
)
);
$combined = array();
$i = 0;
$combined[0] = array_shift($times);
foreach($times AS $time){
if($combined[$i]['end']>=$time['start']) $combined[$i]['end'] = $time['end'];
else{
$i++;
$combined[$i] = $time;
}
}
var_dump($combined);
|
|
|
|
|
Date :
2014-01-02 11:19:55 |
By :
itpcc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เพิ่มเงื่อนไขในการตรวจสอบเวลาขั้นต้นครับ
Code (PHP)
<?php
$times = array(
array(
"start" => 100,
"end" => 1700
),
array(
"start" => 1900,
"end" => 2100
),
array(
"start" => 1800,
"end" => 2300
)
);
$combined = array();
$i = 0;
$combined[0] = array_shift($times);
foreach($times AS $time){
$pass = false;
if($combined[$i]['end']>=$time['start']){
$combined[$i]['end'] = $time['end'];
$pass = true;
}
if($combined[$i]['start']>=$time['start']){
$combined[$i]['start'] = $time['start'];
$pass = true;
}
if(!$pass){
$i++;
$combined[$i] = $time;
}
}
var_dump($combined);
|
|
|
|
|
Date :
2014-01-02 13:50:07 |
By :
itpcc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ไม่บอกแล้วครับ ง่ายนิดเดียว ลองหาดู
|
|
|
|
|
Date :
2014-01-02 15:50:18 |
By :
itpcc |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้แล้ว ขอบคุณค่ะ
|
|
|
|
|
Date :
2014-01-02 17:23:20 |
By :
^nueng^ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|