我有一个数组的客户访问信息。数组的访问是升序的订单日期. .我要知道最后的探访记录但不应该是今天。
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
)
)
这里我想要得到第一个…可以有任意次数的访问。
$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);
您需要编写一个函数或方法来对对象数组进行排序。它必须接收一个对象数组作为参数,然后,例如,创建另一个数组,并一个接一个地添加对象,首先-最新的,从午夜开始,然后第二个…
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);