如何在laravel刀片中显示json数据?

时间:2018-09-18 09:15:04

标签: arrays json laravel multidimensional-array laravel-blade

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"
  ]
]

我只想显示城市名称,纬度和经度。

1 个答案:

答案 0 :(得分: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