public static function arrayCombine(array $first, array $second, $replacement = null, $order = true)
    {
        // Fix for different length
        if (count($first) !== count($second)) {
            $input = array($first, $second);
            $count = array_map('count', $input);

            // Find the largest and lowest array index
            $min = array_keys($count , max($count));
            $max = array_keys($count , min($count));

            // Find indexes
            $min = $min[0];
            $max = $max[0];

            $largest = $input[$min];
            $smallest = $input[$max];

            // Now fix the length
            foreach ($largest as $key => $value) {
                if (!isset($smallest[$key])) {
                    $smallest[$key] = $replacement; 
                }
            }

            $first = $smallest;
            $second = $largest;
        }

        if ($order === true) {
            return array_combine($second, $first);
        } else {
            return array_combine($first, $second);
        }
    }
public static function arrayCombine(array $first, array $second, $replacement = null, $order = true)
    {
        // Fix for different length
        if (count($first) !== count($second)) {
            $input = array($first, $second);
            $count = array_map('count', $input);

            // Find the largest and lowest array index
            $min = array_keys($count , max($count));
            $max = array_keys($count , min($count));

            // Find indexes
            $min = $min[0];
            $max = $max[0];

            $largest = $input[$min];
            $smallest = $input[$max];

            // Now fix the length
            foreach ($largest as $key => $value) {
                if (!isset($smallest[$key])) {
                    $smallest[$key] = $replacement; 
                }
            }

            $first = $smallest;
            $second = $largest;
        }

        if ($order === true) {
            return array_combine($second, $first);
        } else {
            return array_combine($first, $second);
        }
    }
public static function arrayCombine ( array $ first , array $ second , $ replacement = null , $ order = true ) { // Fix for different length if ( count ( $ first ) !== count ( $ second ) ) { $ input = array ( $ first , $ second ) ; $ count = array_map ( 'count' , $ input ) ; // Find the largest and lowest array index $ min = array_keys ( $ count , max ( $ count ) ) ; $ max = array_keys ( $ count , min ( $ count ) ) ; // Find indexes $ min = $ min [ 0 ] ; $ max = $ max [ 0 ] ; $ largest = $ input [ $ min ] ; $ smallest = $ input [ $ max ] ; // Now fix the length foreach ( $ largest as $ key => $ value ) { if ( ! isset ( $ smallest [ $ key ] ) ) { $ smallest [ $ key ] = $ replacement ; } } $ first = $ smallest ; $ second = $ largest ; } if ( $ order === true ) { return array_combine ( $ second , $ first ) ; } else { return array_combine ( $ first , $ second ) ; } }
Combines two arrays even with different length

@param array $first
@param array $second
@param string $replacement Replacement for
@param boolean $order Whether to merge first with second or vice versa
@return array
Combines two arrays even with different length