Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我可以假设以前有人问过这个问题,但我找不到任何问题。
我有一个代表十六进制值的字符串,比如
$sHex = "314E6B";
我想将此字符串尽可能简单/优雅地转换为包含这三个字符的十进制值的数组,即具有值的数组
(49, 78, 107)
我调查了pack, hex2dec,array_split但那些将包括我试图避免的循环。具有一或两行(且无循环)的解决方案是首选。
pack
hex2dec
array_split
代码 :
$sHex = "314E6B"; $aDec = array_map('hexdec', str_split($sHex, 2)); print_r( $aDec );
将输出:
Array ( [0] => 49 [1] => 78 [2] => 107 )