display json data in php from api using post code example
Example 1: send application/json php
$url = 'http://www.example.com/api';
$ch = curl_init($url);
$data = array(
'username' => 'codexworld',
'password' => '123456');
$payload = json_encode(array("user" => $data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
Example 2: how to receive json data in php
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data;