PHP code example of sarphp / return-data-format

1. Go to this page and download the library: Download sarphp/return-data-format 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/ */

    

sarphp / return-data-format example snippets


class Examples
{
    function __construct() {
    }
    function getData(){
        $data = [
            [
                'id' => 1, 
                'name' => 'Jon D',            
            ],
            [
                'id' => 2, 
                'name' => 'Michel N',            
            ]
        ];
        $apiKey = "Aie"; 
        
        return \ReturnDataFormat\Response::success()->message('Data saved successfully!')
                                                     ->data($data)
                                                     ->apiKey($apiKey);
                                                     // Anything you can add here will be in array 
    }
}

$obj = new Examples();
$data = $obj->getData();
print_r($data->toArray()); 
print_r($data->toJson()); 
print_r($data->toSerialize()) ;