How can a HTTP POST request be sent in PHP?

To send a HTTP POST request in PHP, you can use the cURL library which provides functions to make HTTP requests. You can set the request method to POST, specify the URL to send the request to, and include any data to be sent in the request body. After sending the request, you can retrieve the response from the server.

$url = 'http://example.com/api';
$data = array('key1' => 'value1', 'key2' => 'value2');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

curl_close($ch);

echo $response;