如何将键值对添加到数组?
这行不通:
public function getCategorieenAsArray(){
$catList = array();
$query = "SELECT DISTINCT datasource_id, title FROM table";
if ($rs=C_DB::fetchRecordset($query)) {
while ($row=C_DB::fetchRow($rs)) {
if(!empty($row["title"])){
array_push($catList, $row["datasource_id"] ."=>". $row["title"] );
}
}
}
return($catList);
}
因为它给了我:
Array ( [0] => 1=>Categorie 1 [1] => 5=>Categorie 2 [2] => 2=>Caterorie 2 )
我期望:
Array ( [1] =>Categorie 1 [5] => Categorie 2 )
2
代表更多的人可以编辑此问题并修复换行符吗?
—
Brian Ramsay