亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Use the primary key value of the data as the index of the associative array to obtain the data
王林
王林 2023-07-16 17:41:35
0
2
8393

After executing the fetch query, I got an array of results:

[row_choice] => Array
  (
    [0] => Array
      (
        [id] => 277410
        [text_value] => Two Wheel
      )
    [1] => Array
      (
        [id] => 277411
        [text_value] => Three Wheel
      )
    [2] => Array
      (
        [id] => 277412
        [text_value] => Four Wheel
      )
  )

How do I get an array of results like this?

[row_choice] => Array
  (
    [277410] => Array
      (
        [id] => 277410
        [text_value] => Two Wheel
      )
    [277411] => Array
      (
        [id] => 277411
        [text_value] => Three Wheel
      )
    [277412] => Array
      (
        [id] => 277412
        [text_value] => Four Wheel
      )
  )

What should I do?

My question is

SELECT id,text_value FROM answer_choice


王林
王林

有朋自遠(yuǎn)方來,雖遠(yuǎn)必誅!

reply all(2)
大瓶可樂@php.cn


從SQL查詢中直接實(shí)現(xiàn)這個(gè)功能是不可能的,但是你可以檢索所有的數(shù)據(jù),然后重新映射數(shù)組。

使用PHP 5.5的array_column()函數(shù),你可以做類似以下的操作:


$myarray['row_choice'] = array_combine(
    array_column($myarray['row_choice'], 'id'),
    $myarray['row_choice']
);

對(duì)于較早版本的PHP,可以使用array_map()函數(shù)來代替。

$myarray['row_choice'] = array_combine(
    array_map(
        function($value) {
            return $value['id'];
        },
        $myarray['row_choice']
    ),
    $myarray['row_choice']
);

你應(yīng)該按照以下方式創(chuàng)建一個(gè)新的數(shù)組變量。

$recArr = array();

while ($records = mysqli_fetch_array($query)) {
    $recArr[$records['id']] = $records;
}

var_dump($recArr);
P粉804184459

Hello, Mr. Wang, I very much agree with your skills and hope to have further communication opportunities with you. Can you please add us via WeChat or email?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template