What is the function of socket_create in PHP when working with UDP packets?

When working with UDP packets in PHP, the function socket_create can be used to create a socket for communication over a UDP protocol. This function allows you to specify the address family, socket type, and protocol for the socket. By using socket_create, you can establish a connection for sending and receiving UDP packets in your PHP application.

// Create a UDP socket
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

if (!$socket) {
    echo "Failed to create socket: " . socket_strerror(socket_last_error());
} else {
    echo "Socket created successfully!";
    
    // Use the socket for sending and receiving UDP packets
}

// Don't forget to close the socket when done
socket_close($socket);