PHP code example of crackersw / weather

1. Go to this page and download the library: Download crackersw/weather library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

crackersw / weather example snippets


use CrackerSw\Weather\Weather;
$key = "xxxxxxxxxxxxxxxxxxxxx";
$weather = new Weather($key);

$response = $weather->getLiveWeather("无锡");

$response = $weather->getForecastsWeather("无锡");

$response = $weather->getLiveWeather("无锡","xml");

array|string getWeather(string $city,$string $type = "base",string $format = "json")

    .
    .
    .
    "weather" => [
        "key" => env("WEATHER_API_KEY"),
    ],

WEATHER_API_KEY=xxxxxxxxxxxxxxxxxxxxx

    .
    .
    .
    public function getWeather(Weather $weather) 
    {
        $response = $weather->getLiveWeather('无锡');
    }
    .
    .
    .

    .
    .
    .
    public function getWeather(Weather $weather) 
    {
        $response = app('weather')->getLiveWeather('无锡');
    }
    .
    .
    .