PHP | pack() Function Last Updated : 27 Sep, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The pack() function is an inbuilt function in PHP which is used to pack the given parameter into a binary string in a given format. Syntax: pack( $format, $arguments ) Parameters: This function accepts two parameters as mentioned above and described below: $format: It is required parameter. It specifies the format to be used while packing the data. The possible values of format are: a - string which is NUL-padded A - string which is SPACE-padded h - low nibble first Hex string H - high nibble first Hex string c - signed character C - unsigned character s - signed short (16 bit, machine byte order) S - unsigned short ( 16 bit, machine byte order) n - unsigned short ( 16 bit, big endian byte order) v - unsigned short ( 16 bit, little endian byte order) i - signed integer (machine dependent byte order and size) I - unsigned integer (machine dependent byte order and size) l - signed long ( 32 bit, machine byte order) L - unsigned long ( 32 bit, machine byte order) N - unsigned long ( 32 bit, big endian byte order) V - unsigned long ( 32 bit, little endian byte order) f - float (machine dependent representation and size) d - double (machine dependent representation and size) x - NUL byte X - Back up one byte Z - string which is NUL-padded @ - NUL-fill to absolute position $arguments: It is Optional parameter. It specifies one or more arguments to be packed. Return Value: It returns a binary string containing data. Note: This function is available on PHP 4.0.0 and newer version. Program 1: This program uses C format to format the input parameter. php <?php echo pack("C13", 71, 69, 69, 75, 83, 70, 79, 82, 71, 69, 69, 75, 83); ?> Output: GEEKSFORGEEKS Program 2: This program uses A format to format the input parameter. php <?php echo pack("A3", 71898); ?> Output: 718 Program 3: This program uses i format to format the input parameter. php <?php echo pack("i3", 56, 49, 54); ?> Output: 816 Reference: https://www.php.net/manual/en/function.pack.php Comment More infoAdvertise with us Next Article PHP list() Function G gekcho Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP krsort() Function The krsort() function is an inbuilt function in PHP which is used to sort an array by key in reverse order according to its index values. It sorts in a way that relation between indices and values is maintained. Syntax: bool krsort( $array, $sorting_type ) Parameters: This function accepts two param 2 min read PHP array_pad() Function The array_pad() is a builtin function in PHP and is used to pad a value fixed number of time onto an array. This function inserts an element specified number of times into an array either at front or back. Syntax: array array_pad($input_array, $input_size, $values) Parameters: This function accepts 3 min read PHP list() Function The list() function is an inbuilt function in PHP which is used to assign array values to multiple variables at a time. This function will only work on numerical arrays. When the array is assigned to multiple values, then the first element in the array is assigned to the first variable, second to th 2 min read PHP implode() Function The implode() is a built-in function in PHP and is used to join the elements of an array. implode() is an alias for PHP | join() function and works exactly same as that of join() function.If we have an array of elements, we can use the implode() function to join them all to form one string. We join 2 min read PHP | zip_open() Function The zip_open() function is an inbuilt function in PHP which is used to open a zip archive for reading. The zip_open() function creates a new stream and establishes a connection between the stream and a Zip Archive. The filename is sent as a parameter to the zip_open() function and it returns a valid 2 min read PHP | unpack() Function The unpack() function is an inbuilt function in PHP which is used to unpack from a binary string into the respective format. Syntax: array unpack( $format, $data, $offset ) Parameters: This function accepts three parameters as mentioned above and described below: $format: It is required parameter. I 3 min read Like