メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Pdo::simpleArray

Get the specific column's key and value array of executed select query

Description​

public array Pdo::simpleArray( string $keyName, string $valueName )

Returns key => value pairs built from two columns of every row of the last SELECT, for example for <select> options.

Arguments​

NameData typeDefaultRemarks
$keyNamestringColumn to use as the key
$valueNamestringColumn to use as the value

Example​

Controller
$db = new \Fegg\Database\Pdo();

$titles = $db->setItem('news_id, title')->select('cms_news')->execute()->simpleArray('news_id', 'title');
// -> array(1 => 'A', 2 => 'B', 3 => 'C')