gpt4 book ai didi

php - 如何创建具有键值对的数组?

转载 作者:IT老高 更新时间:2023-10-28 11:48:05 26 4
gpt4 key购买 nike

如何将键值对添加到数组中?

这行不通:

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  ) 

最佳答案

$data =array();
$data['user_code'] = 'JOY' ;
$data['user_name'] = 'JOY' ;
$data['user_email'] = 'joy@cargomar.org';

关于php - 如何创建具有键值对的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1138359/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com