我是 codeigniter 框架的新手。我正在使用 foreach 循環在數組內和數組內創建一個數組,以從 3 個表中獲取記錄。我已經像這樣制作數組Array([devices] => Array ( [0] => Array ( [id] => 1 [device_name] => Smartphone [device_image] => device-images/1d57a675edbb2ff97c5bc35fce27517c.png [device_icon] => device-images/325af5a3587cdfc8f35ae345a2d432a3.png [all_manufacturers] => Array ( [0] => Array ( [id] => 1 [fk_device_id] => 1 [manufacture] => Apple [models] => Array ( [0] => Array ( [id] => 1 [fk_deviceid] => 1 [fk_manufactureid] => 1 [model_name] => iPhone 11 Pro Max ) [1] => Array ( [id] => 2 [fk_deviceid] => 1 [fk_manufactureid] => 1 [model_name] => iPhone 11 Pro )
1 回答

烙印99
TA貢獻1829條經驗 獲得超13個贊
最后一個數組沒有設置“all_manufacturers”,因此錯誤是您試圖設置 $all_manufacturers 而不檢查它是否已設置。
刪除設備循環頂部的這一行:
$all_manufacturers = $device["all_manufacturers"];
然后更改這段代碼:
<?php if ($all_manufacturers) { foreach ($all_manufacturers as $manufacture) { ?>
對此:
if (!empty($device["all_manufacturers"])) { foreach ($device["all_manufacturers"] as $manufacture) {
- 1 回答
- 0 關注
- 125 瀏覽
添加回答
舉報
0/150
提交
取消