0

I have two arrays stored in single variable i want to retrieve data via for-each loop, problem is name index is giving error. Please view below code.

Array

Array
(
    [name] =>  special
    [Cat_id] => 59
)
 Array
(
    [singleproduct] => Array
        (
            [product_id] => 52
            [thumb] => http://localhost/swefloraProject/upload/image/cache/catalog/birthday/home-product-01-80x80.png
            [name] => gift flowers
            [description] => when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has ..
            [price] => $0.00
            [special] => 
            [tax] => $0.00
            [minimum] => 1
            [rating] => 0
            [href] => http://localhost/Project/upload/index.php?route=product/product&product_id=52
        )

)

This is loop

foreach($categories as $category){ 
print_r($category['name']);
}

Error

Notice: Undefined index: name in
Ayaz Ali Shah
  • 634
  • 2
  • 7
  • 16

1 Answers1

0
foreach($categories as $key=> $category){ 
   print_r($key); // prints "name" on first iteration
   print_r($category); // prints "special" on first iteration
}
  • This is not actually an answer but rather a debugging help since it shows you the keys of the iteration which can help you understand why things aren't working, I would not use this as an answer but I would definitely use this for debugging (I would just `print_r($categories)` to see what's in the array all together tho ^.^) – SidOfc Dec 03 '15 at 15:07