How to create an array of integers from a hexstring in php? -
i can suppose question has been asked before, cannot find any.
i have string representing hexadecimal values, like
$shex = "314e6b"; i want convert string simple/elegant possible array containing decimal values of these 3 characters, i.e. array values
(49, 78, 107) i looked pack, hex2dec, array_split include loops trying avoid. solution 1 or 2 lines (and no loop) preferred.
code :
$shex = "314e6b"; $adec = array_map('hexdec', str_split($shex, 2)); print_r( $adec ); will output :
array ( [0] => 49 [1] => 78 [2] => 107 )
Comments
Post a Comment