I am trying to output some content from my DB table, i successfully made a query and also return controller code but when i am trying ouput it in my view, what i tried
<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>
ERROR
Notice: Array to string conversion in C:\\xampp\\htdocs\\usa\\catalog\\view\\theme\\usadevims\\template\\product\\compare.tpl on line 72ArrayNotice: Array to string conversion in C:\\xampp\\htdocs\\usa\\catalog\\view\\theme\\usadevims\\template\\product\\compare.tpl on line 72ArrayNotice: Array to string conversion in C:\\xampp\\htdocs\\usa\\catalog\\view\\theme\\usadevims\\template\\product\\compare.tpl on line 72Array
and here the var_dump of my variable
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 references to an array. Try:
echo $manufacturer['name'];
or
echo $manufacturer['manufacturer_id];
As you can see on your var_dump
, your variable $products[$product['product_id']]['manufacturers']
is an array composed by three other arrays. So each iteration of your loop will assign an array to $manufacturer variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.