What is the best way to extract and use an ID from a JSON response in PHP for use in another API URL?

To extract and use an ID from a JSON response in PHP for use in another API URL, you can decode the JSON response using json_decode() function, access the ID value using the appropriate key, and then construct the new API URL with the extracted ID.

// Assume $jsonResponse contains the JSON response
$response = json_decode($jsonResponse, true);

if(isset($response['id'])) {
    $id = $response['id'];
    
    // Construct the new API URL with the extracted ID
    $newApiUrl = "https://api.example.com/resource/{$id}";
    
    // Now you can use $newApiUrl for further API requests
    echo $newApiUrl;
}