public static function project(array $input, $key, bool $strictKeyCheck = true) : array
    {
        $projection = [];

        foreach ($input as $itemKey => $item) {
            self::ensureIsArray($item, 'a value in $input was not an array');

            if (array_key_exists($key, $item)) {
                $projection[$itemKey] = $item[$key];
            } elseif ($strictKeyCheck) {
                throw new \InvalidArgumentException('key was not in one of the $input arrays');
            }
        }

        return $projection;
    }
public static function project(array $input, $key, bool $strictKeyCheck = true) : array
    {
        $projection = [];

        foreach ($input as $itemKey => $item) {
            self::ensureIsArray($item, 'a value in $input was not an array');

            if (array_key_exists($key, $item)) {
                $projection[$itemKey] = $item[$key];
            } elseif ($strictKeyCheck) {
                throw new \InvalidArgumentException('key was not in one of the $input arrays');
            }
        }

        return $projection;
    }
public static function project ( array $ input , $ key , bool $ strictKeyCheck = true ) : array { $ projection = [ ] ; foreach ( $ input as $ itemKey => $ item ) { self :: ensureIsArray ( $ item , 'a value in $input was not an array' ) ; if ( array_key_exists ( $ key , $ item ) ) { $ projection [ $ itemKey ] = $ item [ $ key ] ; } elseif ( $ strictKeyCheck ) { throw new \ InvalidArgumentException ( 'key was not in one of the $input arrays' ) ; } } return $ projection ; }
Projects values of a key into an array.

if $input = [
['key 1' => 'item 1 value 1', 'key 2' => 'item 1 value 2'],
['key 1' => 'item 2 value 1', 'key 2' => 'item 2 value 2'],
['key 1' => 'item 3 value 1'],
]
and $key = 'key 2'
and $strictKeyCheck = false

then return ['item 1 value 2', 'item 2 value 2']

but if $strictKeyCheck = true then an InvalidArgumentException occurs since 'key 2' wasnt in item 3

@param array $input the array to project from
@param string|integer $key the key which values we are to project
@param boolean $strictKeyCheck ensure key is in each $input array or not

@return array the projection

@throws \InvalidArgumentException if a value in $input was not an array
@throws \InvalidArgumentException if a key was not in one of the $input arrays
Projects values of a key into an array .