Change endianness of a decimal number in PHP
<?php
/**
* Change endianness of the given decimal number.
*
* @param int $num
*
* @return int
*/
function num_endianness($num) {
$hex = dechex($num);
if (strlen($hex) <= 2) {
return $num;
}
return hexdec(unpack('H*', strrev(pack('H*', $hex)))[1]);
}