Answers for "web api return json example in php"

PHP
1

web api return json example in php

$option = $_GET['option'];

if ( $option == 1 ) {
    $data = [ 'a', 'b', 'c' ];
    // will encode to JSON array: ["a","b","c"]
    // accessed as example in JavaScript like: result[1] (returns "b")
} else {
    $data = [ 'name' => 'God', 'age' => -1 ];
    // will encode to JSON object: {"name":"God","age":-1}  
    // accessed as example in JavaScript like: result.name or result['name'] (returns "God")
}

header('Content-type: application/json');
echo json_encode( $data );
Posted by: Guest on November-03-2020
0

php create json as request for call another api

$upgradeFlutterButton = new FlutterButton("UPGRADE", "2", "com.COMPANY.APP_NAME");

        $postData = array(
            'app_id' => 1,
            'actions' => [
              $upgradeFlutterButton
            ],
            'user_id' => 2,
        );

        $objectRequest = new \Illuminate\Http\Request();
        $objectRequest->setMethod('POST');
        $objectRequest->request->add($postData);

        return $objectRequest;
Posted by: Guest on June-28-2021

Browse Popular Code Answers by Language