且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP在foreach循环中将平面转换为嵌套的多维数组

更新时间:2022-05-15 02:45:58

您快到了,只需按以下方式更改 foreach 循环,

You're almost there, just change your foreach loop in the following way,

foreach ($dimsDesc as $desc) {
    $descriptions[$desc['indcode']]['indlabel'] = $desc['indlabel'];
    $descriptions[$desc['indcode']]['description'] = $desc['description'];
}

或者,

foreach ($dimsDesc as $desc) {
    $descriptions[$desc['indcode']] = array('indlabel' => $desc['indlabel'], 'description' => $desc['description']);
}

这里是文档,

  • Creating/modifying arrays with square bracket syntax