php echo json
<?php
$data = ['name' => 'John', 'age' => 35];
header('Content-type: Application/json');
echo json_encode($data);
php echo json
<?php
$data = ['name' => 'John', 'age' => 35];
header('Content-type: Application/json');
echo json_encode($data);
access json with php
<?php
$data = '{
"name": "Aragorn",
"race": "Human"
}';
$character = json_decode($data);
echo $character->name;
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 );
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us