PHP code example of alphaolomi / json-placeholder

1. Go to this page and download the library: Download alphaolomi/json-placeholder 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/ */

    

alphaolomi / json-placeholder example snippets


$api = new Json\Api();

$users = $api->users()->list();

foreach($users as $user) {
    echo $user->name;
}

$users =  (new Json\Api())->users()->list();

print_r($users);

// array:10 [
//   0 => array:8 [
//     "id" => 1
//     "name" => "Leanne Graham"
//     "username" => "Bret"
//     "email" => "[email protected]"
//     "address" => array:5 [▶]
//     "phone" => "1-770-736-8031 x56442"
//     "website" => "hildegard.org"
//     "company" => array:3 [▶]
//   ]
//   1 => array:8 [▶]
// ]

$api = new Json\Api();

$results = $api->users()->paginate();

foreach($results as $result) {
    // Handle result
    echo $result->name;
}