How can I create an array with key value pairs?

后端 未结 6 578
名媛妹妹
名媛妹妹 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:03

    Use the square bracket syntax:

    if (!empty($row["title"])) {
        $catList[$row["datasource_id"]] = $row["title"];
    }
    

    $row["datasource_id"] is the key for where the value of $row["title"] is stored in.

提交回复
热议问题