How can I create an array with key value pairs?

后端 未结 6 567
名媛妹妹
名媛妹妹 2020-12-23 16:00

How can I add key value pairs to an array?

This won\'t work:

public function getCategorieenAsArray(){

    $catList = array();

    $query = \"SELECT         


        
6条回答
  •  独厮守ぢ
    2020-12-23 16:16

    My PHP is a little rusty, but I believe you're looking for indexed assignment. Simply use:

    $catList[$row["datasource_id"]] = $row["title"];
    

    In PHP arrays are actually maps, where the keys can be either integers or strings. Check out PHP: Arrays - Manual for more information.

提交回复
热议问题