src/Traits/Collections.php
public static function pluck($collection, string $property): array
    {
        $result = array_map(function ($value) use ($property) {
            if (is_array($value) && isset($value[$property])) {
                return $value[$property];
            } elseif (is_object($value) && isset($value->{$property})) {
                return $value->{$property};
            }
            foreach (__::split($property, '.') as $segment) {
                if (is_object($value)) {
                    if (isset($value->{$segment})) {
                        $value = $value->{$segment};
                    } else {
                        return null;
                    }
                } else {
                    if (isset($value[$segment])) {
                        $value = $value[$segment];
                    } else {
                        return null;
                    }
                }
            }

            return $value;
        }, (array)$collection);

        return array_values($result);
    }
public static function pluck($collection, string $property): array
    {
        $result = array_map(function ($value) use ($property) {
            if (is_array($value) && isset($value[$property])) {
                return $value[$property];
            } elseif (is_object($value) && isset($value->{$property})) {
                return $value->{$property};
            }
            foreach (__::split($property, '.') as $segment) {
                if (is_object($value)) {
                    if (isset($value->{$segment})) {
                        $value = $value->{$segment};
                    } else {
                        return null;
                    }
                } else {
                    if (isset($value[$segment])) {
                        $value = $value[$segment];
                    } else {
                        return null;
                    }
                }
            }

            return $value;
        }, (array)$collection);

        return array_values($result);
    }
public static function pluck ( $ collection , string $ property ) : array { $ result = array_map ( function ( $ value ) use ( $ property ) { if ( is_array ( $ value ) && isset ( $ value [ $ property ] ) ) { return $ value [ $ property ] ; } elseif ( is_object ( $ value ) && isset ( $ value -> { $ property } ) ) { return $ value -> { $ property } ; } foreach ( __ :: split ( $ property , '.' ) as $ segment ) { if ( is_object ( $ value ) ) { if ( isset ( $ value -> { $ segment } ) ) { $ value = $ value -> { $ segment } ; } else { return null ; } } else { if ( isset ( $ value [ $ segment ] ) ) { $ value = $ value [ $ segment ] ; } else { return null ; } } } return $ value ; } , ( array ) $ collection ) ; return array_values ( $ result ) ; }
Returns an array of values belonging to a given property of each item in a collection.

@usage $a = [
['foo' => 'bar',  'bis' => 'ter' ],
['foo' => 'bar2', 'bis' => 'ter2'],
];

__::pluck($a, 'foo');
>> ['bar', 'bar2']

@param array|object $collection array or object that can be converted to array
@param string       $property   property name

@return array
Returns an array of values belonging to a given property of each item in a collection .