public static function compressArray(array $array, $keys = null) {
        $return = array();

        if ($keys && !is_array($keys)) {
            $keys = array($keys);
        }
        else if (!$keys) {
            $keys = array();
        }

        foreach ($array as $ky => $value) {
            if (!is_array($value) && stristr($value, '__:DS:__')) {
                $value = explode('__:DS:__', $value);
            }

            if (is_array($value)) {
                $return = array_merge_recursive($return, self::compressArray($value, $keys));
                continue;
            }

            if (($keys && in_array($ky, $keys)) || !$keys) {
                if (array_key_exists($ky, $return)) {
                    if (is_array($return[$ky]))
                        $return[$ky][] = $value;
                    else
                        $return[$ky] = array($return[$ky], $value);
                } else {
                    $return[$ky] = $value;
                }
            }
        }
        return $return;
    }
public static function compressArray(array $array, $keys = null) {
        $return = array();

        if ($keys && !is_array($keys)) {
            $keys = array($keys);
        }
        else if (!$keys) {
            $keys = array();
        }

        foreach ($array as $ky => $value) {
            if (!is_array($value) && stristr($value, '__:DS:__')) {
                $value = explode('__:DS:__', $value);
            }

            if (is_array($value)) {
                $return = array_merge_recursive($return, self::compressArray($value, $keys));
                continue;
            }

            if (($keys && in_array($ky, $keys)) || !$keys) {
                if (array_key_exists($ky, $return)) {
                    if (is_array($return[$ky]))
                        $return[$ky][] = $value;
                    else
                        $return[$ky] = array($return[$ky], $value);
                } else {
                    $return[$ky] = $value;
                }
            }
        }
        return $return;
    }
public static function compressArray ( array $ array , $ keys = null ) { $ return = array ( ) ; if ( $ keys && ! is_array ( $ keys ) ) { $ keys = array ( $ keys ) ; } else if ( ! $ keys ) { $ keys = array ( ) ; } foreach ( $ array as $ ky => $ value ) { if ( ! is_array ( $ value ) && stristr ( $ value , '__:DS:__' ) ) { $ value = explode ( '__:DS:__' , $ value ) ; } if ( is_array ( $ value ) ) { $ return = array_merge_recursive ( $ return , self :: compressArray ( $ value , $ keys ) ) ; continue ; } if ( ( $ keys && in_array ( $ ky , $ keys ) ) || ! $ keys ) { if ( array_key_exists ( $ ky , $ return ) ) { if ( is_array ( $ return [ $ ky ] ) ) $ return [ $ ky ] [ ] = $ value ; else $ return [ $ ky ] = array ( $ return [ $ ky ] , $ value ) ; } else { $ return [ $ ky ] = $ value ; } } } return $ return ; }
Compresses an array of arrays into a single array merging identical keys
into one with their values as an array
@param array $array
@param string|int|array $keys
Compresses an array of arrays into a single array merging identical keys into one with their values as an array