我是 codeigniter 框架的新手。我正在使用 foreach 循環(huán)在數(shù)組內(nèi)和數(shù)組內(nèi)創(chuàng)建一個(gè)數(shù)組,以從 3 個(gè)表中獲取記錄。我已經(jīng)像這樣制作數(shù)組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貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊
最后一個(gè)數(shù)組沒(méi)有設(shè)置“all_manufacturers”,因此錯(cuò)誤是您試圖設(shè)置 $all_manufacturers 而不檢查它是否已設(shè)置。
刪除設(shè)備循環(huán)頂部的這一行:
$all_manufacturers = $device["all_manufacturers"];
然后更改這段代碼:
<?php if ($all_manufacturers) { foreach ($all_manufacturers as $manufacture) { ?>
對(duì)此:
if (!empty($device["all_manufacturers"])) { foreach ($device["all_manufacturers"] as $manufacture) {
- 1 回答
- 0 關(guān)注
- 137 瀏覽
添加回答
舉報(bào)
0/150
提交
取消