1

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"
      }
    }
1
  • it is $products array or $product array? Commented May 8, 2015 at 16:41

1 Answer 1

7

$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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.