遍历simplexml对象并将其附加

时间:2019-01-11 22:55:07

标签: php simplexml

对于这个问题,我深表歉意。我一直在寻找解决方案,但找不到任何东西。但是我正在尝试遍历从API调用得到的simplexml。 API并不是最好的API,因此当日期超过午夜时,它将完全取消这些订单。因此,要解决该问题,我还必须获得第二天的订单,然后对订单进行一次foreach,然后在要获取目标日期的日期上执行if。在每个循环中,我希望它接受simplexml对象并将其放入变量中,然后附加每个新变量,因此最后我有了一个只有正确日期的新对象。

我尝试删除特定节点,但这似乎比在每次迭代结束时将它们组合起来要复杂得多。

if (strtotime($thisFri) >= strtotime($today)) {
    $params = array(
        "shiftStart" => $thisFri . " 00:00:00",
        "shiftEnd" => $thisSat . "12:00:00",
        "status" => "filled"
    );
    $clearConnect->setParameters($params);
    $clearConnect->setResultType('xml');
    $shiftResult = $clearConnect->sendRequest('getOrders'); //gets orders
    $friShifts = simplexml_load_string($shiftResult); //puts the results in to xml
    foreach ($friShifts->order as $shift) { //iterates through each order
        $startLong = new DateTime($shift->shiftStartTime); //figuring out dates
        $start = $startLong->format('Y-m-d');
        $endLong = new DateTime($shift->shiftEndTime);
        $end = $endLong->format('Y-m-d');
        if ($start == $thisFri) { //if to run through all orders with proper start date

这就是我的位置。 $ friShifts是simplexml,其中包含一堆看起来像这样的订单。此后还会发生更多事情,但这基本上是我想要的。我希望将正确日期的每次迭代放入新的simplexml中,然后通过我的其他函数运行。

SimpleXMLElement Object
(
    [orderId] => 3988445
    [status] => filled
    [shiftStartTime] => 2019-01-11T07:00:00
    [shiftEndTime] => 2019-01-11T15:30:00
    [tempId] => 57921
    [firstName] => SimpleXMLElement Object
        (
        )

    [lastName] => SimpleXMLElement Object
        (
        )

    [clientId] => 1543
    [clientName] => SimpleXMLElement Object
        (
        )

    [regionName] => SimpleXMLElement Object
        (
        )

    [orderSpecialty] => School
    [orderCertification] => SLP
    [floor] => SimpleXMLElement Object
        (
        )

    [shiftNumber] => 1
    [note] => SimpleXMLElement Object
        (
        )

    [payrollNumber] => SimpleXMLElement Object
        (
        )

    [lessLunchMin] => SimpleXMLElement Object
        (
        )

    [dateTimeCreated] => 2018-08-06T17:03:34
    [takenBy] => 480
    [bookedByUserId] => 480
    [orderTypeId] => 1
    [orderType] => SimpleXMLElement Object
        (
        )

    [city] => Media
    [state] => xx
    [zipCode] => xxxxx
    [orderSourceID] => SimpleXMLElement Object
        (
        )

    [orderSourceName] => SimpleXMLElement Object
        (
        )

    [lt_orderID] => 0
    [dateTimeModified] => 2018-08-06T17:03:34
    [subjectID] => SimpleXMLElement Object
        (
        )

    [subject] => SimpleXMLElement Object
        (
        )

)```


0 个答案:

没有答案
相关问题