If your hexadecimal values ββare always strings, you can use the following function:
function swapEndianness($hex) { return implode('', array_reverse(str_split($hex, 2))); }
Agreed, this is not the most efficient, but the code is pretty elegant, in my opinion. In addition, it works with all sizes of numbers.
source share