1

我有一系列客户访问信息。数组按日期升序排列访问。我需要获得最后一次访问。但不应该是今天。

    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
                           )
     )

在这里,我想获得第一个...可以有任意数量的访问。我只展示了两个...

4

3 回答 3

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);
于 2013-04-30T11:44:24.637 回答
0

您需要编写一个函数或方法来对对象数组进行排序。它必须接收对象数组作为参数,然后,例如,创建另一个对象,并在那里一个接一个地添加对象,第一个 - 最新的,从午夜开始并返回,然后是第二个......

于 2013-04-30T11:44:01.710 回答
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);
于 2013-04-30T11:52:10.803 回答