Create PHP array from MySQL column

前端 未结 11 990
花落未央
花落未央 2020-12-03 07:54

mysql_fetch_array will give me an array of a fetched row. What\'s the best way generate an array from the values of all rows in one column?

11条回答
  •  情歌与酒
    2020-12-03 08:17

    There is no function to do this using the mysql extension, you can do this:

    $result = array();
    while ($row = mysql_fetch_array($r, MYSQL_NUM)) {
        $result[] = $row[0];
    }
    

    It is apparently marginally faster to fetch the columns in a numerically indexed array, and there is no real benefit here to having the associative array format.

提交回复
热议问题