PHP CURL DELETE request

To send a DELETE request with PHP using cURL, you can use the following code:

<?php

// Set up cURL
$ch = curl_init('http://example.com/api/resource');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Set up DELETE request
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");

// Set up data for DELETE request (if applicable)
$data = ['key1' => 'value1', 'key2' => 'value2'];
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

// Send the request
$response = curl_exec($ch);

// Check for errors
if ($response === false) {
  die(curl_error($ch));
}

// Decode the response
$responseData = json_decode($response, true);

// Print the response data
print_r($responseData);

Watch a course Learn object oriented PHP

This will send a DELETE request to the specified URL, with the specified data (if applicable). The response from the server will be saved in the $response variable, and can be decoded and printed as shown in the example.

Note that the server you are sending the request to must be set up to handle DELETE requests and process the data correctly.