wppaste
WordPress

wpdb::get_col( string|null $query = null, int $x = 0 ): array

Since
0.71
Source
wp-includes/class-wpdb.php:3139
Retrieves one column from the database.

Description

Executes a SQL query and returns the column from the SQL result.If the SQL result contains more than one column, the column specified is returned.If $query is null, the specified column from the previous SQL result is returned.

Parameters

$querystring|nulloptional
SQL query. Defaults to previous query.Default: null
$xintoptional
Column to return. Indexed from 0. Default 0.Default: 0

Return

array
Database query result. Array indexed from 0 by SQL result row number.

Uses · 3

Source

	public function get_col( $query = null, $x = 0 ) {		if ( $query ) {			if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {				$this->check_current_query = false;			} 			$this->query( $query );		} 		$new_array = array();		// Extract the column values.		if ( $this->last_result ) {			for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) {				$new_array[] = $this->get_var( null, $x, $i );			}		}		return $new_array;	}

History

Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wpdb.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.