extract() static public method

Extracts a single column from an array
static public extract ( array $array, string $key ) : array
$array array The source array
$key string The key name of the column to extract
return array The result array with all values from that column.
Exemplo n.º 1
0
 public function testExtract()
 {
     $users = $this->users;
     $usernames = a::extract($users, 'username');
     $this->assertEquals(array('peter', 'paul', 'mary'), $usernames);
 }
Exemplo n.º 2
0
 /**
  * Returns only values from a single column
  *
  * @param string $column
  * @return mixed
  */
 public function column($column)
 {
     $results = $this->query($this->select($column)->order($this->primaryKeyName . ' ASC')->build('select'), array('iterator' => 'array', 'fetch' => 'array'));
     $results = a::extract($results, $column);
     if ($this->iterator == 'array') {
         return $results;
     }
     $iterator = $this->iterator;
     return new $iterator($results);
 }
Exemplo n.º 3
0
 /**
  * Returns only values from a single column
  *
  * @param string $column
  * @return mixed
  */
 public function column($column)
 {
     $sql = new SQL($this->database, $this);
     $primaryKey = $sql->combineIdentifier($this->table, $this->primaryKeyName);
     $results = $this->query($this->select(array($column))->order($primaryKey . ' ASC')->build('select'), array('iterator' => 'array', 'fetch' => 'array'));
     $results = a::extract($results, $column);
     if ($this->iterator == 'array') {
         return $results;
     }
     $iterator = $this->iterator;
     return new $iterator($results);
 }