public static function baseConvert(array $source, $srcBase, $dstBase) {
        if ($dstBase < 2) {
            $message = sprintf('Invalid Destination Base: %d', $dstBase);
            throw new \InvalidArgumentException($message);
        }
        $result = array();
        $count  = count($source);
        while ($count) {
            $itMax     = $count;
            $remainder = $count = $loop = 0;
            while($loop < $itMax) {
                $dividend  = $source[$loop++] + $remainder * $srcBase;
                $remainder = $dividend % $dstBase;
                $res       = ($dividend - $remainder) / $dstBase;
                if ($count || $res) {
                    $source[$count++] = $res;
                }
            }
            $result[] = $remainder;
        }
        return array_reverse($result);
    }
public static function baseConvert(array $source, $srcBase, $dstBase) {
        if ($dstBase < 2) {
            $message = sprintf('Invalid Destination Base: %d', $dstBase);
            throw new \InvalidArgumentException($message);
        }
        $result = array();
        $count  = count($source);
        while ($count) {
            $itMax     = $count;
            $remainder = $count = $loop = 0;
            while($loop < $itMax) {
                $dividend  = $source[$loop++] + $remainder * $srcBase;
                $remainder = $dividend % $dstBase;
                $res       = ($dividend - $remainder) / $dstBase;
                if ($count || $res) {
                    $source[$count++] = $res;
                }
            }
            $result[] = $remainder;
        }
        return array_reverse($result);
    }
public static function baseConvert ( array $ source , $ srcBase , $ dstBase ) { if ( $ dstBase < 2 ) { $ message = sprintf ( 'Invalid Destination Base: %d' , $ dstBase ) ; throw new \ InvalidArgumentException ( $ message ) ; } $ result = array ( ) ; $ count = count ( $ source ) ; while ( $ count ) { $ itMax = $ count ; $ remainder = $ count = $ loop = 0 ; while ( $ loop < $ itMax ) { $ dividend = $ source [ $ loop ++ ] + $ remainder * $ srcBase ; $ remainder = $ dividend % $ dstBase ; $ res = ( $ dividend - $ remainder ) / $ dstBase ; if ( $ count || $ res ) { $ source [ $ count ++ ] = $ res ; } } $ result [ ] = $ remainder ; } return array_reverse ( $ result ) ; }
Convert an array of input blocks to another numeric base

This function was modified from an implementation found on StackOverflow.
Special Thanks to @KeithRandall for supplying the implementation.

@param int[] $source  The source number, as an array
@param int   $srcBase The source base as an integer
@param int   $dstBase The destination base as an integer

@see http://codegolf.stackexchange.com/questions/1620/arb/1626#1626
@return int[] An array of integers in the encoded base
Convert an array of input blocks to another numeric base