How can arrays be serialized and sent via HTTP in PHP for data transfer?
To serialize arrays and send them via HTTP in PHP for data transfer, you can use the `json_encode()` function to convert the array into a JSON string before sending it. On the receiving end, you can use `json_decode()` to convert the JSON string back into an array.
// Serialize the array into a JSON string
$data = json_encode($array);
// Send the data via HTTP
// For example, using cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/api');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$response = curl_exec($ch);
curl_close($ch);
// On the receiving end, decode the JSON string back into an array
$received_data = json_decode($response, true);