extract() static public méthode

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
Résultat array The result array with all values from that column.
Exemple #1
0
 public function testExtract()
 {
     $users = $this->users;
     $usernames = a::extract($users, 'username');
     $this->assertEquals(array('peter', 'paul', 'mary'), $usernames);
 }
Exemple #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);
 }
 /**
  * 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);
 }