且构网

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

PHP多维数组中获取值

更新时间:2023-02-23 11:17:01

这是遍历数组的方式:

foreach($hotels as $row) {
       foreach($row['rooms'] as $k) {
             echo $k['boards']['board_id'];
             echo $k['boards']['price'];
       }
}

您想重复的酒店和房间(那些使用数字索引),因为那些似乎是在这种情况下,集合。其他阵列只能容纳和组属性。

You want to iterate on the hotels and the rooms (the ones with numeric indexes), because those seem to be the "collections" in this case. The other arrays only hold and group properties.