PHP数组到字符串转换错误

Kun*_*ngh 1 php

我试图从我的数据库表中输出一些内容,我成功地进行了查询并返回控制器代码但是当我在我的视图中尝试输出它时,我尝试了什么

 <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>
Run Code Online (Sandbox Code Playgroud)

错误

注意:第72行的C:\ xampp\htdocs\usa\catalog\view\theme\usadevims\template\product\compare.tpl中的数组到字符串转换ArrayNotice:C:\ xampp\htdocs\usa\catalog中的数组到字符串转换第72行的\ view\theme\usadevims\template\product\compare.tplArrayNotice:第72行的C:\ xampp\htdocs\usa\catalog\view\theme\usadevims\template\product\compare.tpl中的数组到字符串转换

这里是我的变量的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"
      }
    }
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 7

$ manufacturer引用数组.尝试:

echo $manufacturer['name'];
Run Code Online (Sandbox Code Playgroud)

要么

echo $manufacturer['manufacturer_id];
Run Code Online (Sandbox Code Playgroud)

正如您所看到的var_dump,您的变量$products[$product['product_id']]['manufacturers']是由其他三个数组组成的数组.因此,循环的每次迭代都会为$ manufacturer变量分配一个数组.