如何将json数据显示到laravel刀片?

问题描述 投票:-1回答:1
public function bar()
{

    $lowm = new LaravelOWM();
    $for = $lowm->getWeatherForecast('lahore');
     $ff= json_decode(json_encode($for),true);
    dd($for);
}

这是我认为多维数组的输出,我只想打印一些东西。告诉我每个循环的答案。

array:3 [▼
  "city" => array:6 [▼
    "id" => 1172451
    "name" => "Lahore"
    "country" => "PK"
    "population" => null
    "lat" => 31.5196
    "lon" => 74.3263
  ]
  "sun" => array:2 [▼
    "rise" => array:3 [▼
      "date" => "2018-09-17 00:48:17.000000"
      "timezone_type" => 3
      "timezone" => "UTC"
    ]
    "set" => array:3 [▼
      "date" => "2018-09-17 13:05:08.000000"
      "timezone_type" => 3
      "timezone" => "UTC"
    ]
  ]
  "lastUpdate" => array:3 [▼
    "date" => "2018-09-17 23:00:29.303267"
    "timezone_type" => 3
    "timezone" => "UTC"
  ]
]

我只想显示城市名称,lat和lon。

arrays json laravel multidimensional-array laravel-blade
1个回答
0
投票

为什么不呢?

public function bar() {
    $lowm = new LaravelOWM();
    $for = $lowm->getWeatherForecast('lahore');
    dump('City: '. $for->city->name);
    dump('Latitude: '. $for->city->lat);
    dump('Longitude: '. $for->city->lon);
}

More Here

© www.soinside.com 2019 - 2024. All rights reserved.