Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:42:47+00:00 2026-06-03T19:42:47+00:00

I have am generating the array at the bottom of this message. I am

  • 0

I have am generating the array at the bottom of this message. I am using CodeIgniter and this array to display heirarchical information via the following view:

<?php foreach($products['top_cats'] as $top_cat): // $top_cat ?>
    <h2><?php echo $top_cat['cat_name']; ?></h2>
    <?php if( ! empty($products['sub_cats'][$top_cat['cat_id']])): ?>
        <?php foreach($products['sub_cats'][$top_cat['cat_id']] as $sub_cat): ?>
            <h3><?php echo $sub_cat['name']; ?></h3>
            <!-- problem below -->
            <?php $this->load->view('products_table_v', $products[$sub_cat['id']][$n]); ?>
            <?php var_dump($n); ?>
        <?php endforeach; ?>
    <?php endif; ?>
<?php endforeach; ?>

$products[top_cats][14] relates to $products[sub_cats][14] and $products[sub_cats][14] relates to $products[products][14] (I hope this makes sense). So I need to pass $products[products][14] to the view when I am in the foreach for $products[sub_cats][14] (again, I hope this makes sense?)…

My problem is that I need to pass the correct sub-sub(-sub) array to the sub-view (which contains a good working foreach loop). I cannot get my head around how to give the array the the sub-view (I have gone code blind).

Please help.

Array
(
    [top_cats] =&gt; Array
        (
            [14] =&gt; Array
                (
                    [cat_id] =&gt; 14
                    [cat_name] =&gt; Alcopops
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [2] =&gt; Array
                (
                    [cat_id] =&gt; 2
                    [cat_name] =&gt; Beers and Lagers
                    [cat_desc] =&gt; <p>hh</p>
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 0
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [79] =&gt; Array
                (
                    [cat_id] =&gt; 79
                    [cat_name] =&gt; Household
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [5] =&gt; Array
                (
                    [cat_id] =&gt; 5
                    [cat_name] =&gt; Soft Drinks
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [4] =&gt; Array
                (
                    [cat_id] =&gt; 4
                    [cat_name] =&gt; Spirits
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

            [3] =&gt; Array
                (
                    [cat_id] =&gt; 3
                    [cat_name] =&gt; Wines
                    [cat_desc] =&gt; 
                    [cat_featured] =&gt; n
                    [cat_parent_id] =&gt; 
                    [cat_sort_order] =&gt; 
                    [category_active] =&gt; y
                )

        )

    [sub_cats] =&gt; Array
        (
            [3] =&gt; Array
                (
                    [25] =&gt; Array
                        (
                            [id] =&gt; 25
                            [name] =&gt; Champagne and Sparkling Wines
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 3
                        )

                    [22] =&gt; Array
                        (
                            [id] =&gt; 22
                            [name] =&gt; Australian Wines
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 3
                        )


                )

            [14] =&gt; Array
                (
                    [30] =&gt; Array
                        (
                            [id] =&gt; 30
                            [name] =&gt; White Rum
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 4
                        )

                    [32] =&gt; Array
                        (
                            [id] =&gt; 32
                            [name] =&gt; Liquers
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 4
                        )

                )

            [2] =&gt; Array
                (
                    [8] =&gt; Array
                        (
                            [id] =&gt; 8
                            [name] =&gt; Canned Lager
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [12] =&gt; Array
                        (
                            [id] =&gt; 12
                            [name] =&gt; Bottled Beer
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [10] =&gt; Array
                        (
                            [id] =&gt; 10
                            [name] =&gt; Bitter Cans
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [7] =&gt; Array
                        (
                            [id] =&gt; 7
                            [name] =&gt; Super Beers
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [13] =&gt; Array
                        (
                            [id] =&gt; 13
                            [name] =&gt; Cider
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                    [9] =&gt; Array
                        (
                            [id] =&gt; 9
                            [name] =&gt; Stout
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 2
                        )

                )

            [] =&gt; Array
                (
                    [5] =&gt; Array
                        (
                            [id] =&gt; 5
                            [name] =&gt; Soft Drinks
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 
                        )

                    [79] =&gt; Array
                        (
                            [id] =&gt; 79
                            [name] =&gt; Household
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 
                        )

                    [14] =&gt; Array
                        (
                            [id] =&gt; 14
                            [name] =&gt; Alcopops
                            [desc] =&gt; 
                            [cat_parent_id] =&gt; 
                        )

                )

        )

    [products] =&gt; Array
        (
            [25] =&gt; Array
                (
                    [1347] =&gt; Array
                        (
                            [product_id] =&gt; 1347
                            [category_id] =&gt; 25
                            [name] =&gt; Asti Spumante Martini
                            [description] =&gt; 
                            [source_price] =&gt; 29.00
                            [source_pack_size] =&gt; 6
                            [source_item_size] =&gt; 75.00
                            [source_unit_id] =&gt; 2
                            [resale_price] =&gt; 7.00
                            [resale_pack_size] =&gt; 1
                            [percentage_return] =&gt; 22.59
                            [product_code] =&gt; WNAS001
                            [product_image] =&gt; 1347_.jpg
                            [current_stock] =&gt; 5
                            [stock_level_id] =&gt; 0
                            [featured] =&gt; y
                            [active] =&gt; y
                            [so_member_of_group_id] =&gt; 0
                            [discount_amount] =&gt; 3.50
                            [created_at] =&gt; 2009-07-22 10:21:57
                            [modified_at] =&gt; 
                            [product_unit_id] =&gt; 2
                            [unit_name] =&gt; Centilitre
                            [unit_symbol] =&gt; cl
                            [stock_levels_id] =&gt; 
                            [stock_levels_name] =&gt; 
                            [cat_id] =&gt; 25
                            [cat_name] =&gt; Champagne and Sparkling Wines
                            [cat_desc] =&gt; 
                            [cat_featured] =&gt; n
                            [cat_parent_id] =&gt; 3
                            [cat_sort_order] =&gt; 
                            [category_active] =&gt; y
                        )

                    [1566] =&gt; Array
                        (
                            [product_id] =&gt; 1566
                            [category_id] =&gt; 25
                            [name] =&gt; Blossom Hill Zinfandel Sparkling
                            [description] =&gt; 
                            [source_price] =&gt; 29.99
                            [source_pack_size] =&gt; 6
                            [source_item_size] =&gt; 70.00
                            [source_unit_id] =&gt; 2
                            [resale_price] =&gt; 8.49
                            [resale_pack_size] =&gt; 1
                            [percentage_return] =&gt; 29.35
                            [product_code] =&gt; WNBH010
                            [product_image] =&gt; 
                            [current_stock] =&gt; 30
                            [stock_level_id] =&gt; 
                            [featured] =&gt; n
                            [active] =&gt; y
                            [so_member_of_group_id] =&gt; 
                            [discount_amount] =&gt; 0.00
                            [created_at] =&gt; 2011-03-21 10:35:47
                            [modified_at] =&gt; 
                            [product_unit_id] =&gt; 2
                            [unit_name] =&gt; Centilitre
                            [unit_symbol] =&gt; cl
                            [stock_levels_id] =&gt; 
                            [stock_levels_name] =&gt; 
                            [cat_id] =&gt; 25
                            [cat_name] =&gt; Champagne and Sparkling Wines
                            [cat_desc] =&gt; 
                            [cat_featured] =&gt; n
                            [cat_parent_id] =&gt; 3
                            [cat_sort_order] =&gt; 
                            [category_active] =&gt; y
                        )


                )

            [22] =&gt; Array
                (
                    [1020] =&gt; Array
                        (
                            [product_id] =&gt; 1020
                            [category_id] =&gt; 22
                            [name] =&gt; Auction House Cabernet Sauvignon Merlot (Aus)
                            [description] =&gt; 
                            [source_price] =&gt; 20.00
                            [source_pack_size] =&gt; 6
                            [source_item_size] =&gt; 75.00
                            [source_unit_id] =&gt; 2
                            [resale_price] =&gt; 5.00
                            [resale_pack_size] =&gt; 1
                            [percentage_return] =&gt; 27.18
                            [product_code] =&gt; WNAH008
                            [product_image] =&gt; 1020_.jpg
                            [current_stock] =&gt; 35
                            [stock_level_id] =&gt; 0
                            [featured] =&gt; y
                            [active] =&gt; y
                            [so_member_of_group_id] =&gt; 0
                            [discount_amount] =&gt; 0.75
                            [created_at] =&gt; 2008-03-10 14:56:16
                            [modified_at] =&gt; 
                            [product_unit_id] =&gt; 2
                            [unit_name] =&gt; Centilitre
                            [unit_symbol] =&gt; cl
                            [stock_levels_id] =&gt; 
                            [stock_levels_name] =&gt; 
                            [cat_id] =&gt; 22
                            [cat_name] =&gt; Australian Wines
                            [cat_desc] =&gt; 
                            [cat_featured] =&gt; n
                            [cat_parent_id] =&gt; 3
                            [cat_sort_order] =&gt; 
                            [category_active] =&gt; y
                        )

                )

        )

)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:42:48+00:00Added an answer on June 3, 2026 at 7:42 pm
    foreach($products['top_cats'] as $top_cat): // $top_cat ?>
        <h2><?php echo $top_cat['cat_name']; ?></h2>
        <?php if( ! empty($products['sub_cats'][$top_cat['cat_id']])): ?>
            <?php foreach($products['sub_cats'][$top_cat['cat_id']] as $sub_cat): ?>
                <h3><?php echo $sub_cat['name']; ?></h3>
    
                // Replaced bit
                <?php if( ! empty($products['products'][$sub_cat['id']])): ?>
                    <?php $this->load->view('products_table_v', $products['products'][$sub_cat['id']]); ?>
                <?php endif; ?>
    
            <?php endforeach; ?>
        <?php endif; ?>
    <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following array with a structure within each array (see this jsfiddle
So I have this simple PHP loop that is generating html table data with
I have a PHP loop that's auto-generating an array to INSERT into a table.
I have a preg_match_all that is generating an array of urls from a string.
I have php generating html and I want to create layers. Basically I want
So far I have learned about generating thread dump and heap dump using jstack
I have a large nested array that I'm generating from parsing a CSV file
I have a piece of PHP code that is generating over 6000 queries to
I'm generating plain simple links with CakePHP's HtmlHelper the following way: $html->link(Newest, array( 'controller'
Hi have an array of cities and want to create a google map using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.