Last active
July 7, 2020 19:36
-
-
Save cosminpopescu14/e5e55eee5eaabd63416c3b876f57ade8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use GuzzleHttp\Client; | |
use GuzzleHttp\Exception\GuzzleException; | |
require "vendor/autoload.php"; | |
$url = "http://jsonplaceholder.typicode.com/todos"; | |
$client = new Client(); | |
try { | |
$response = $client->request('GET', $url); | |
$content = $response->getBody(); | |
$json = json_decode($content); | |
//var_dump($json[0]->completed); | |
$completed = 0; | |
$notCompleted = 0; | |
foreach ($json as $elem) { | |
/*$comleted = array_filter($elem, fn($var) => $elem->completed !== true); //nu merge ca in java cu filter | |
print_r($comleted);*/ | |
if ($elem->completed === true) { | |
$completed++; | |
} | |
if ($elem->completed === false) { | |
$notCompleted++; | |
} | |
} | |
echo $completed . PHP_EOL; | |
echo $notCompleted; | |
} catch (GuzzleException $e) { | |
echo $e->getMessage(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "vendor_name/untitled4", | |
"description": "description", | |
"minimum-stability": "stable", | |
"license": "proprietary", | |
"authors": [ | |
{ | |
"name": "cosmi", | |
"email": "cosmin.popescu93@gmail.com" | |
} | |
], | |
"require": { | |
"guzzlehttp/guzzle": "^7.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment