Skip to main content
Version: Fegg 5.x (next)

Model::column

Get one column of every matching row

Description​

public array Model::column( string $column, [ string $key = null ] )

Returns the values of $column of every matching row, as a list or, with $key, keyed by another column. order and limit apply. Both names must be column names (title or cms_news.title), or InvalidArgumentException is thrown.

Arguments​

NameData typeDefaultRemarks
$columnstringColumn to return
$keystringnullColumn to use as the array key

Example​

Controller
$model = new Model(false, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));

$ids = $model->where('category = ?', 2)->column('news_id');
// -> array(2, 5, 8, ...)

$titles = $model->order('news_id')->column('title', 'news_id');
// -> array(1 => 'News 1', 2 => 'News 2', ...)