Collection::pluck PHP Method

pluck() public method

Extracts all values for a single field into a new array
public pluck ( string $field, $split = null, $unique = false ) : array
$field string
return array
    public function pluck($field, $split = null, $unique = false)
    {
        $result = array();
        foreach ($this->data as $item) {
            $row = $this->extractValue($item, $field);
            if ($split) {
                $result = array_merge($result, str::split($row, $split));
            } else {
                $result[] = $row;
            }
        }
        if ($unique) {
            $result = array_unique($result);
        }
        return array_values($result);
    }

Usage Example

Example #1
0
 public static function combine($type, $files, $compress = false)
 {
     $root = panel::instance()->roots()->assets() . DS . $type;
     $cache = new Media($root . DS . 'panel.' . $type);
     $media = new Collection(array_map(function ($file) use($root) {
         return new Media($root . DS . str_replace('/', DS, $file));
     }, $files));
     // get the max modification date
     $modified = max($media->pluck('modified'));
     if (is_writable($root) and (!$cache->exists() or $cache->modified() < $modified)) {
         $cache->remove();
         $content = '';
         foreach ($media as $asset) {
             $content .= $asset->read() . PHP_EOL;
         }
         if ($compress) {
             $content = static::compress($content);
         }
         f::write($root . DS . 'panel.' . $type, $content);
     }
     if ($cache->exists()) {
         return $type(panel()->urls()->{$type}() . '/panel.' . $type . '?v=' . panel()->version());
     }
     return $type(array_map(function ($item) use($type) {
         return 'panel/assets/' . $type . '/' . $item;
     }, $files));
 }
All Usage Examples Of Collection::pluck