I'm newbie in PHP and Opencart and I want to show a list of products with their appropriate categories, but I don't know how to manage it with array:
$data['heading_title'] = $this->language->get('heading_title');
$results = $this->model_catalog_profile->getProducts();
if ($results) {
foreach ($results as $result) {
// Categories
$categories = $this->model_profile_profile->getProductCategories($result['product_id']);
$data['product_categories'] = array();
foreach ($categories as $category_id) {
$category_info = $this->model_profile_category->getCategory($category_id);
if ($category_info) {
$data['product_categories'][] = array(
'category_id' => $category_info['category_id'],
'name' => $category_info['name']
);
}
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'product_categories' => $data['product_categories'][]
)
);
}
return $this->load->view('module/latest', $data);
}
And here is the code view:
<?php foreach ($products as $product) { ?>
<div class="profile-thumb transition">
<div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div>
<div class="caption">
<h4><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></h4>
<p><?php echo $product['description']; ?></p>
<div id="product-category" class="" style="height: 120px; overflow: auto;">
<?php foreach ($product_categories as $product_category) { ?>
">
array_push($data['products'], $new_arr);$data['products'][] = array(....)usearray_push($data['products'], $new_arr);[]from'product_categories' => $data['product_categories'][]. It should be'product_categories' => $data['product_categories']