php - Undefined index when accessing multi-dimensional array -


i having multi-dimensional array. when access undefined index can't see doing wrong. appreciate if has glue devastating quite while now. thanks!

dump:

array ( [922] => array     (         [products] => array             (                 [169] => http://www.golf-safari.com/golf_regions/cape_town.asp             )          [company] => stdclass object             (                 [id] => 922                 [category_id] => 42                 [language_id] => 1                 [shipping_from_id] => 0                 [name] => golf-safari.com                 [logo] =>                  [company_id] => 922                 [area_id] => 414                 [country_id] =>                  [city_id] => 260                 [product_id] => 169                 [url] => http://www.golf-safari.com/golf_regions/cape_town.asp                 [likes] => 0                 [dislikes] => 0                 [views] => 0             )      ) ) 

my access code:

<?php foreach($items $cmp_id => $company):       $item = $company['company']; // throws undefined index company       $item = $company['products']; // throws undefined index product ?> <div class="title" title="<?= $item->company ?>">  

i not getting div error thrown on $company['company']

thanks answers! don't know whats wrong. assumed when there dump produced dump can accessed, apparently not. added preparation code below.

my preparation code:

foreach($rows $row)     {                            if($row->product_id && !in_array($row->product_id, $products)){             array_push($products, $row->product_id);                         }                    $products_count[$row->product_id][] = '1';                $ids[$row->id] = $row->id; //store every company id, in order avoid repetitions count variables            $items[$row->id]['products'][$row->product_id] = $row->url; //cities products                        $items[$row->id]['company'] = $row;      }             if($products && is_array($products)){                 $query = db::table('products');                 $query->select('id', "name_$this->language product");                 $query->wherein('id', $products);                 $product_names = $query->get();     }               $sub['items'] = array(                 'items' => $items,                 'product_names'=> $product_names             ); 

  1. $item = $company['product']; // throws undefined index product

in here passing wrong key use $item = $company['products'];

print_r($company['products']);

  1. in $company['company'] object can access values following way echo $company['company']->name;

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -