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
从SQL查询中直接实现这个功能是不可能的,但是你可以检索所有的数据,然后重新映射数组。
使用PHP 5.5的array_column()函数,你可以做类似以下的操作:
对于较早版本的PHP,可以使用array_map()函数来代替。
你应该按照以下方式创建一个新的数组变量。
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?