protected function _index($collection, $name)
    {
        $indexes = [];
        foreach ($collection as $key => $entity) {
            if (is_object($entity)) {
                if ($entity->{$name}) {
                    $indexes[(string) $entity->{$name}] = $key;
                }
            } else {
                if (isset($entity[$name])) {
                    $indexes[(string) $entity[$name]] = $key;
                }
            }
        }
        return $indexes;
    }
protected function _index($collection, $name)
    {
        $indexes = [];
        foreach ($collection as $key => $entity) {
            if (is_object($entity)) {
                if ($entity->{$name}) {
                    $indexes[(string) $entity->{$name}] = $key;
                }
            } else {
                if (isset($entity[$name])) {
                    $indexes[(string) $entity[$name]] = $key;
                }
            }
        }
        return $indexes;
    }
protected function _index ( $ collection , $ name ) { $ indexes = [ ] ; foreach ( $ collection as $ key => $ entity ) { if ( is_object ( $ entity ) ) { if ( $ entity -> { $ name } ) { $ indexes [ ( string ) $ entity -> { $ name } ] = $ key ; } } else { if ( isset ( $ entity [ $ name ] ) ) { $ indexes [ ( string ) $ entity [ $ name ] ] = $ key ; } } } return $ indexes ; }
Indexes a collection.

@param  mixed  $collection An collection to extract index from.
@param  string $name       The field name to build index for.
@return Array              An array of indexes where keys are `$name` values and
values the corresponding index in the collection.
Indexes a collection .