Skip to content

Instantly share code, notes, and snippets.

@cosminpopescu14
Last active July 7, 2020 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosminpopescu14/e5e55eee5eaabd63416c3b876f57ade8 to your computer and use it in GitHub Desktop.
Save cosminpopescu14/e5e55eee5eaabd63416c3b876f57ade8 to your computer and use it in GitHub Desktop.
<?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();
}
{
"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