array_column

Supported Versions: PHP 5 >= 5.5.0, PHP 7, PHP 8
Return the values from a single column in the input array
<?php array_column(array $array, int|string|null $column_key, int|string|null $index_key = null): array
<?php         $tableName = $this->argument('table') ?: select(

            'Which table would you like to inspect?',

            array_column($tables, 'name')

        );



        $table = Arr::first($tables, fn ($table) => $table['name'] === $tableName);
<?php     public function newPivot(array $attributes = [], $exists = false)

    {

        $attributes = array_merge(array_column($this->pivotValues, 'value', 'column'), $attributes);



        $pivot = $this->related->newPivot(

            $this->parent, $attributes, $this->table, $exists, $this->using
<?php     public function processColumns($results, $sql = '')

    {

        $hasPrimaryKey = array_sum(array_column($results, 'primary')) === 1;



        return array_map(function ($result) use ($hasPrimaryKey, $sql) {

            $result = (object) $result;
<?php     public function getTableListing()

    {

        return array_column($this->getTables(), 'name');

    }
<?php     public function getColumnListing($table)

    {

        return array_column($this->getColumns($table), 'name');

    }
<?php     public function getIndexListing($table)

    {

        return array_column($this->getIndexes($table), 'name');

    }
<?php     public function dropAllTables()

    {

        $tables = array_column($this->getTables(), 'name');



        if (empty($tables)) {

            return;
<?php     public function dropAllViews()

    {

        $views = array_column($this->getViews(), 'name');



        if (empty($views)) {

            return;
<?php             $table->string('name')->index();

        });



        $indexes = array_column($connection->getSchemaBuilder()->getIndexes('table1'), 'name');



        $this->assertContains('table1_name_index', $indexes, 'name');

    }
<?php             $table->string('name')->index();

        });



        $indexes = array_column($connection->getSchemaBuilder()->getIndexes('table1'), 'name');



        $this->assertContains('example_table1_name_index', $indexes);

    }
<?php         $tables = Schema::getTables();



        $this->assertCount(2, $tables);

        $this->assertEquals(['migrations', 'users'], array_column($tables, 'name'));



        $columns = Schema::getColumnListing('users');
<?php         $tables = Schema::getTables();



        $this->assertCount(2, $tables);

        $this->assertEquals(['migrations', 'users'], array_column($tables, 'name'));



        $columns = Schema::getColumnListing('users');
<?php         DB::statement('create table groups_1 partition of groups for values with (modulus 2, remainder 0)');

        DB::statement('create table groups_2 partition of groups for values with (modulus 2, remainder 1)');



        $tables = array_column(Schema::getTables(), 'name');



        $this->assertContains('groups', $tables);

        $this->assertContains('groups_1', $tables);
<?php         $this->artisan('migrate:install');



        $tables = array_column(Schema::getTables(), 'name');



        $this->assertNotContains('groups', $tables);

        $this->assertNotContains('groups_1', $tables);
<?php         $tables = Schema::getTables();



        $this->assertEmpty(array_diff(['foo', 'bar', 'baz'], array_column($tables, 'name')));



        if (in_array($this->driver, ['mysql', 'mariadb', 'pgsql'])) {

            $this->assertNotEmpty(array_filter($tables, function ($table) {