How can PHP's pack() and unpack() functions be used to handle binary data conversion in PHP, specifically for signed integers?

When dealing with binary data conversion in PHP, specifically for signed integers, the pack() function can be used to convert data into a binary string, while the unpack() function can be used to unpack the binary data back into its original format. To handle signed integers, the 'l' format code can be used in pack() to represent a signed long integer. When unpacking, the 'l' format code can also indicates that the data should be interpreted as a signed long integer.

// Convert signed integer to binary data
$signedInteger = -12345;
$binaryData = pack('l', $signedInteger);

// Unpack binary data back to signed integer
$unpackedInteger = unpack('l', $binaryData)[1];

echo "Original signed integer: $signedInteger\n";
echo "Unpacked signed integer: $unpackedInteger\n";