public static function arrayPartition(array $raw, $key, $keepKey = true)
    {
        $result = array();

        foreach ($raw as $index => $collection) {
            // Make the the root partition exists
            if (!isset($collection[$key])) {
                throw new LogicException(sprintf(
                    'The key "%s" does not exist in provided collection', $key
                ));
            }

            // Extract module' name as a key and put the rest into its values
            $target = array($collection[$key] => $collection);

            
            foreach ($target as $module => $array) {
                // When doesn't exist, then need to create a one
                if (!isset($result[$module])) {
                    $result[$module] = array();
                }

                if ($keepKey == false) {
                    unset($array[$key]);
                }

                $result[$module][] = $array;
            }
        }

        return $result;
    }
public static function arrayPartition(array $raw, $key, $keepKey = true)
    {
        $result = array();

        foreach ($raw as $index => $collection) {
            // Make the the root partition exists
            if (!isset($collection[$key])) {
                throw new LogicException(sprintf(
                    'The key "%s" does not exist in provided collection', $key
                ));
            }

            // Extract module' name as a key and put the rest into its values
            $target = array($collection[$key] => $collection);

            
            foreach ($target as $module => $array) {
                // When doesn't exist, then need to create a one
                if (!isset($result[$module])) {
                    $result[$module] = array();
                }

                if ($keepKey == false) {
                    unset($array[$key]);
                }

                $result[$module][] = $array;
            }
        }

        return $result;
    }
public static function arrayPartition ( array $ raw , $ key , $ keepKey = true ) { $ result = array ( ) ; foreach ( $ raw as $ index => $ collection ) { // Make the the root partition exists if ( ! isset ( $ collection [ $ key ] ) ) { throw new LogicException ( sprintf ( 'The key "%s" does not exist in provided collection' , $ key ) ) ; } // Extract module' name as a key and put the rest into its values $ target = array ( $ collection [ $ key ] => $ collection ) ; foreach ( $ target as $ module => $ array ) { // When doesn't exist, then need to create a one if ( ! isset ( $ result [ $ module ] ) ) { $ result [ $ module ] = array ( ) ; } if ( $ keepKey == false ) { unset ( $ array [ $ key ] ) ; } $ result [ $ module ] [ ] = $ array ; } } return $ result ; }
Drops an array into partitions

@param array $raw Raw array
@param string $key The key to be considered as partition
@param boolean $keepKey Whether to keep key in output
@throws \LogicException if unknown partition key supplied
@return array Dropped array
Drops an array into partitions