我有一個(gè)具有以下值的二維數(shù)組: [ 'id' => 12, 'title' => 'the title', //and a few other key => value ], [ 'id' => 13, 'title' => 'the title 13', // and a few other key => value ],...最后,我需要一個(gè)只有id 和 title的多維數(shù)組[ $item['id'] => $item['title'], ...]通常,我會(huì)做一個(gè)簡(jiǎn)單的 foreach 來(lái)實(shí)現(xiàn)這一點(diǎn),但我現(xiàn)在想使用 php 函數(shù)。我已經(jīng)這樣做了,但是有正確的方法嗎?$list = array_combine(array_column($list_forms, 'id'), array_column($list_forms, 'title'));
1 回答

慕仙森
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
第三個(gè)參數(shù)是:array_column
$list?=?array_column($list_forms,?'title',?'id');
- 1 回答
- 0 關(guān)注
- 91 瀏覽
添加回答
舉報(bào)
0/150
提交
取消