我有一个这样的数据结构:
array (size=10)
1 =>
array (size=2)
'fdate' => string '11/05/12' (length=8)
'ftime' => string '11:13' (length=5)
2 =>
array (size=2)
'fdate' => string '11/05/12' (length=8)
'ftime' => string '11:13' (length=5)
3 =>
array (size=2)
'fdate' => string '11/05/12' (length=8)
'ftime' => string '11:50' (length=5)
4 =>
array (size=2)
'fdate' => string '11/05/12' (length=8)
'ftime' => string '11:51' (length=5)
5 =>
array (size=2)
'fdate' => string '11/07/12' (length=8)
'ftime' => string '09:11' (length=5)
6 =>
array (size=2)
'fdate' => string '11/07/12' (length=8)
'ftime' => string '09:12' (length=5)
7 =>
array (size=2)
'fdate' => string '11/07/12' (length=8)
'ftime' => string '10:29' (length=5)
8 =>
array (size=2)
'fdate' => string '11/08/12' (length=8)
'ftime' => string '11:06' (length=5)
9 =>
array (size=2)
'fdate' => string '11/08/12' (length=8)
'ftime' => string '11:06' (length=5)
10 =>
array (size=2)
'fdate' => string '11/08/12' (length=8)
'ftime' => string '11:07' (length=5)
在这种情况下,我需要评估并得出每个日期的第一个和最后一个 ftime 值
fdate ftime1 ftime2
11/05/12, 11:13, 11:51
11/07/12, 09:11, 10:29
11/08/12, 11:06, 11:07
我有一个这样的循环:
$struct = array();
$i = 1;
foreach($recs as $row){
$struct[$i]['fdate'] = $row->fdate;// store fdate
$struct[$i]['ftime1'] = $row->ftime;// store initial ftime
$currentfdate = $row->fdate; // use $currentfdate in comparison to $row->fdate
if($currentfdate <> $row->fdate){
$struct[$i]['ftime2'] = $row->ftime;// store last ftime
}
$i++;
}
我不确定如何确定 fdate 何时更改以触发 ftime2 的存储。