我正在访问一系列客户访问信息。数组正以升序进行访问 订单日期..我需要最后一次访问..但它不应该是今天。
stdClass Object
(
[0] => stdClass Object
(
[ID] => 39334
[ClassID] => 3193
[StartDateTime] => 2013-04-29T06:00:00
[LateCancelled] =>
[EndDateTime] => 2013-04-29T06:45:00
)
[1] => stdClass Object
(
[ID] => 39334
[ClassID] => 3193
[StartDateTime] => 2013-04-30T06:00:00
[LateCancelled] =>
[EndDateTime] => 2013-04-30T06:45:00
)
)
在这里,我想得到第一个...... 可以有任意数量的访问。我只有两个......
答案 0 :(得分:2)
$whatIneed = false;
foreach($myObj as $obj){
// If this is today object just break, and object from previous loop is what you need
if(date('dmY')==date('dmY',strtotime($obj->StartDateTime))) break;
// saving object in loop into variable
$whatIneed = $obj;
}
print_r($whatIneed);
答案 1 :(得分:0)
您需要编写一个函数或方法来对对象数组进行排序。它必须接收对象数组作为参数,然后,例如,创建另一个对象,并逐个添加对象,第一个 - 最新的,从午夜开始,然后是第二个......
答案 2 :(得分:0)
foreach($obj as $valobj){
// if curentdate is greater than db visit date then insert into array
if(strtotime(date('Y-m-d')) > strtotime(date('Y-m-d',$valobj->StartDateTime))){
$arr[] = $valobj;
}
}
print_r($arr);