[英]PHP Array to string conversion error
我正在嘗試從數據庫表中輸出一些內容,我成功地進行了查詢並返回了控制器代碼,但是當我嘗試在視圖中輸出時,我嘗試了什么
<tr>
<?php foreach ($products as $product) { ?>
<td>
<pre>
<?php
var_dump($products[$product['product_id']]['manufacturers']);
foreach ($products[$product['product_id']]['manufacturers'] as $manufacturer) {
echo $manufacturer;
} ?>
</pre>
</td>
<?php } ?>
</tr>
錯誤
注意:第72行上的C:\\ xampp \\ htdocs \\ usa \\ catalog \\ view \\ theme \\ usadevims \\ template \\ product \\ compare.tpl中的數組到字符串的轉換注意:C:\\ xampp \\ htdocs \\ usa \\ catalog中的數組到字符串的轉換第72Array行上的\\ view \\ theme \\ usadevims \\ template \\ product \\ compare.tpl注意:C:\\ xampp \\ htdocs \\ usa \\ catalog \\ view \\ theme \\ usadevims \\ template \\ product \\ compare.tpl在第72Array行上的數組到字符串的轉換
這是我的變量的var_dump
array(3) {
[0]=>
array(2) {
["name"]=>
string(5) "Apple"
["manufacturer_id"]=>
string(1) "8"
}
[1]=>
array(2) {
["name"]=>
string(3) "HTC"
["manufacturer_id"]=>
string(1) "5"
}
[2]=>
array(2) {
["name"]=>
string(4) "Sony"
["manufacturer_id"]=>
string(2) "10"
}
}
$ manufacturer引用數組。 嘗試:
echo $manufacturer['name'];
要么
echo $manufacturer['manufacturer_id];
正如您在var_dump
上看到的那樣,變量$products[$product['product_id']]['manufacturers']
是由其他三個數組組成的數組。 因此,循環的每次迭代都會為$ manufacturer變量分配一個數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.