Home > Article > Backend Development > How to convert array to hexadecimal in php
Conversion method: 1. Use the implode() function to convert the array into a string. The connector between elements is a null character. The syntax is "implode($arr)" or "implode("",$arr) "; 2. Use the bin2hex() function to convert the string into a hexadecimal value, the syntax is "bin2hex (string)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, the array cannot be directly converted to Hexadecimal, but can be converted indirectly with the help of strings.
First use the implode() function to convert the array into a string
Then use the bin2hex() function to convert the string into hexadecimal System value
Implementation example:
<?php header("content-type:text/html;charset=utf-8"); $array = array(1,2,3,"a","Hello","World"); var_dump($array); $bin = implode("",$array); echo "字符串:".$bin."<br>"; $hex = bin2hex($bin); echo "十六进制值:".$hex."<br>"; ?>
Description:
implode() function returns an array element The combined string. (The alias of the implode() function is also called the join() function.)
implode(separator,array)
Parameter | Description |
---|---|
separator | Optional. Specifies what is placed between array elements. Default is "" (empty string). |
array | Required. Arrays to be combined into strings. |
#bin2hex() function converts a string of ASCII characters into a hexadecimal value.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert array to hexadecimal in php. For more information, please follow other related articles on the PHP Chinese website!