a::extract PHP Méthode

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.
    static function extract($array, $key)
    {
        $output = array();
        foreach ($array as $a) {
            if (isset($a[$key])) {
                $output[] = $a[$key];
            }
        }
        return $output;
    }

Usage Example

Exemple #1
0
 public function testExtract()
 {
     $users = $this->users;
     $usernames = a::extract($users, 'username');
     $this->assertEquals(array('peter', 'paul', 'mary'), $usernames);
 }
All Usage Examples Of a::extract