在 Laravel 中使用 N 级解析 FedEx 多维数组时出错

FedEx Web 服务返回以下多维数组:


array(2) {

  ["Meta"]=>

  array(2) {

    ["Code"]=>

    int(200)

    ["ErrorMessage"]=>

    string(0) ""

  }

  ["Data"]=>

  array(6) {

    ["Errors"]=>

    array(0) {

    }

    ["ShipmentId"]=>

    string(12) "801000933796"

    ["Destination"]=>

    array(6) {

      ["Addr1"]=>

      NULL

      ["Addr2"]=>

      NULL

      ["City"]=>

      string(10) "PARSIPPANY"

      ["State"]=>

      string(2) "NJ"

      ["PostalCode"]=>

      NULL

      ["Country"]=>

      string(2) "US"

    }

    ["EstimatedDelivery"]=>

    string(0) ""

    ["DeliveredTime"]=>

    string(25) ""

    ["Packages"]=>

    array(1) {

      [0]=>

      array(2) {

        ["TrackingNumber"]=>

        string(12) "xxsssdfsds"

        ["Activity"]=>

        array(19) {

          [0]=>

          array(8) {

            ["Description"]=>

            string(9) "Delivered"

            ["Location"]=>

            array(4) {

              ["City"]=>

              string(10) "PARSIPPANY"

              ["State"]=>

              string(2) "NJ"

              ["PostalCode"]=>

              string(5) "07054"

              ["Country"]=>

              string(2) "US"

            }

            ["Time"]=>

            string(25) "2019-07-08T09:31:00-04:00"

            ["StatusCode"]=>

            string(2) "DL"

            ["StatusTypeCode"]=>

            NULL

            ["StatusDescription"]=>

            string(9) "Delivered"

            ["Signatory"]=>

            string(7) "name"

            ["ProofOfDelivery"]=>

使用 Laravel PHP 提取单行值一切正常,但我找不到提取 N 级值的方法,例如 [Packages] 中显示的值


扬帆大鱼
浏览 100回答 1
1回答

炎炎设计

控制器$packages = [];foreach($response['Data']['Packages'] as $p => $package) {&nbsp; &nbsp; foreach($package['Activity'] as $a => $activity) {&nbsp; &nbsp; &nbsp; &nbsp; $packages[$p]['Activity'][] = [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Description' => $activity['Description'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'City' => $activity['Location']['City'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'State' => $activity['Location']['State'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Country' => $activity['Location']['Country'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Time' => $activity['Time'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'StatusCode' => $activity['StatusCode'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'StatusTypeCode' => $activity['StatusTypeCode'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'StatusDescription' => $activity['StatusDescription'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Signatory' => $activity['Signatory'],&nbsp; &nbsp; &nbsp; &nbsp; ];&nbsp; &nbsp; }}return view('ship2b/trackresults', compact('packages'));看法@foreach ($packages as $package)&nbsp; &nbsp; @foreach ($package['Activity'] as $event)&nbsp; &nbsp; &nbsp; &nbsp; <div>{{ $event['Description'] }}</div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; <div>{{ $event['City'] }}</div>&nbsp; &nbsp; &nbsp; &nbsp; <div>{{ $event['State'] }}</div>&nbsp; &nbsp; &nbsp; &nbsp; <div>{{ $event['Country'] }}</div>&nbsp; &nbsp; &nbsp; &nbsp; <div>{{ $event['Time'] }}</div>&nbsp; &nbsp; &nbsp; &nbsp; <div>{{ $event['StatusCode'] }}</div>&nbsp; &nbsp; &nbsp; &nbsp; <div>{{ $event['StatusTypeCode'] }}</div>&nbsp; &nbsp; &nbsp; &nbsp; <div>{{ $event['StatusDescription'] }}</div>&nbsp; &nbsp; &nbsp; &nbsp; <div>{{ $event['Signatory'] }}</div>&nbsp; &nbsp; @endforeach@endforeach
打开App,查看更多内容
随时随地看视频慕课网APP