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

  • Home
  • SEARCH
  • 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 6054405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:08:57+00:00 2026-05-23T08:08:57+00:00

I’m trying to create a multidimensional array that contains an index that it contains

  • 0

I’m trying to create a multidimensional array that contains an index that it contains some information, the items should be linked to its respective index.

Something like:

Category-01 (Image, url1, url2)
- 01 Product (name, url1, url2, url3)
- 02 Product (name, url1, url2, url3)
- 03 Product (name, url1, url2, url3)
Category-02 (Image, url1, url2)
- 04 Product (name, url1, url2, url3)
- 05 Product (name, url1, url2, url3)
- 06 Product (name, url1, url2, url3)

I’ve got so far (changing a file that I used as a basis) was:

<?php
$categories = array( 
    "01" => array( 
        array("name" => "01", "mirror1" => "#URL011", "mirror2" => "#URL021", "mirror3" => "#URL031",), 
        array("name" => "02", "mirror1" => "#URL012", "mirror2" => "#URL022", "mirror3" => "#URL032",), 
        array("name" => "03", "mirror1" => "#URL013", "mirror2" => "#URL023", "mirror3" => "#URL033",), 
    ), 
    "02" => array( 
        array("name" => "04", "mirror1" => "#URL01", "mirror2" => "#URL02", "mirror3" => "#URL03",), 
        array("name" => "05", "mirror1" => "#URL01", "mirror2" => "#URL02", "mirror3" => "#URL03",), 
    ),
    "03" => array( 
        array("name" => "06", "mirror1" => "#URL01", "mirror2" => "#URL02", "mirror3" => "#URL03",), 
        array("name" => "07", "mirror1" => "#URL01", "mirror2" => "#URL02", "mirror3" => "#URL03",), 
    ),
); 
// Setup the preprocessing. 
$numColumns = 99; 
$columnLength = array(); 
$columnData = array(); 
for ($i = 0; $i <= $numColumns; $i++)  
{ $columnLength[] = 0; $columnData[] = ''; } 
// Sort the category array 
ksort($categories); 
// Process our data 
foreach ($categories as $cname => $subcats) { 
    $minLength = $columnLength[0]; 
    $minIndex = 0; 
    for ($i = 1; $i < $numColumns; $i++) { 
        if ($columnLength[$i] < $minLength) { 
            $minLength = $columnLength[$i]; 
            $minIndex = $i; 
        } 
    } 
    $columnLength[$minIndex] += 1 + count($subcat); 
    $columnData[$minIndex] .= '- Categoria '.$cname; 
    foreach($subcats as $subcat) { 
        $columnData[$minIndex] .= 'Produto '.$subcat['name'].' | [<a title="Produto URL01.'.$subcat['name'].'" href="'.$subcat['mirror1'].'">URL01</a>] - [<a title="Produto URL02.'.$subcat['name'].'" href="'.$subcat['mirror2'].'">URL02</a>] - [<a title="Produto URL03.'.$subcat['name'].'" href="'.$subcat['mirror3'].'">URL03</a>]<br/>';


    };
};
// Display our data 
for ($i = 0; $i < $numColumns; $i++) { 
    echo $columnData[$i]; 
} 
?>

PS: I’m still learning and I am new to php.

what I would do is something like this:

$categories = array( 
    "Cat" => "01", "Image" => "image_url", "cat_link1" => "#CATURL01", "cat_link2" => "#CATURL02" => array( 
        array("name" => "01", "mirror1" => "#URL011", "mirror2" => "#URL021", "mirror3" => "#URL031",), 
        array("name" => "02", "mirror1" => "#URL012", "mirror2" => "#URL022", "mirror3" => "#URL032",), 
        array("name" => "03", "mirror1" => "#URL013", "mirror2" => "#URL023", "mirror3" => "#URL033",), 
    ), 
    "Cat" => "02", "Image" => "image_url", "cat_link1" => "#CATURL01", "cat_link2" => "#CATURL02" => array( 
        array("name" => "04", "mirror1" => "#URL01", "mirror2" => "#URL02", "mirror3" => "#URL03",), 
        array("name" => "05", "mirror1" => "#URL01", "mirror2" => "#URL02", "mirror3" => "#URL03",), 
    ),
    "Cat" => "03", "Image" => "image_url", "cat_link1" => "#CATURL01", "cat_link2" => "#CATURL02" => array( 
        array("name" => "06", "mirror1" => "#URL01", "mirror2" => "#URL02", "mirror3" => "#URL03",), 
        array("name" => "07", "mirror1" => "#URL01", "mirror2" => "#URL02", "mirror3" => "#URL03",), 
    ),
);

If that is possible and show the results as:

Category-01 (Image)
- 01 Product (name, url1, url2, url3)
- 02 Product (name, url1, url2, url3)
- 03 Product (name, url1, url2, url3)
catURL1, catURL2
Category-02 (Image)
- 04 Product (name, url1, url2, url3)
- 05 Product (name, url1, url2, url3)
- 06 Product (name, url1, url2, url3)
catURL1, catURL2 

But the script does not work as I want, it shows the products and information, but can not put information on the category / index than the title.

Thanks in advance for help.

With the amendments suggested by inti.

<?php
$categories = array(
    "01" => array(
        "Image" => "product01.jpg",
        "url1" => "SiteProduct",
        "url2" => "SiteSupport",
        "Products" => array(
            array("name" => "01", "url1" => "Site1.1", "url2" => "Site1.2", "url3" => "Site1.3"),
            array("name" => "02", "url1" => "Site2.1", "url2" => "Site2.2", "url3" => "Site2.3"),
            array("name" => "03", "url1" => "Site3.1", "url2" => "Site3.2", "url3" => "Site3.3"),
            array("name" => "04", "url1" => "Site4.1", "url2" => "Site4.2", "url3" => "Site4.3"),
            // and so on the Products...
        )
    ),// and so on the Categories...
    "02" => array(
        "Image" => "product02.jpg",
        "url1" => "SiteProduct",
        "url2" => "SiteSupport",
        "Products" => array(
            array("name" => "05", "url1" => "Site5.1", "url2" => "Site5.2", "url3" => "Site5.3"),
            array("name" => "06", "url1" => "Site6.1", "url2" => "Site6.2", "url3" => "Site6.3"),
            array("name" => "07", "url1" => "Site7.1", "url2" => "Site7.2", "url3" => "Site7.3"),
            array("name" => "08", "url1" => "Site8.1", "url2" => "Site8.2", "url3" => "Site8.3"),
            // and so on the Products...
        )
    ),
);
// Setup the preprocessing. 
$numColumns = 2; 
$columnLength = array(); 
$columnData = array(); 
for ($i = 0; $i <= $numColumns; $i++)  
{ $columnLength[] = 0; $columnData[] = ''; } 
// Sort the category array 
ksort($categories); 
// Process our data 
foreach ($categories as $cname => $cat) { 
    $minLength = $columnLength[0]; 
    $minIndex = 0; 
    for ($i = 1; $i < $numColumns; $i++) { 
        if ($columnLength[$i] < $minLength) { 
            $minLength = $columnLength[$i]; 
            $minIndex = $i; 
        } 
    } 
    $columnLength[$minIndex] += 1 + count($cat); 
    $columnData[$minIndex] .= '<p>'.$cname."</p>\n"; 
    foreach($cat['Products'] as $subcat) { 
        $columnData[$minIndex] .= 'Product '.$subcat['name'].' - '.$subcat['url1'].' - '.$subcat['url2'].' - '.$subcat['url3']."<br/>\n"; 
    } 
} 
// Display our data 
for ($i = 0; $i < $numColumns; $i++) { 
    echo '<div class="column'.($i+1).'">'.$columnData[$i]."</div>\n"; 
} 
?>
  • 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-05-23T08:08:57+00:00Added an answer on May 23, 2026 at 8:08 am

    You have to nest your products in the categories, by adding a Products value to each category. It will contain the products list. The array would look like this:

    $categories = array(
        "01" => array(
            "Image" => "...",
            "url1" => "...",
            "url2" => "...",
            "Products" => array(
                array("name" => "...", "url1" => "...", "url2" => "...", "url3" => "..."),
                // and so on the Products...
            )
        ),
        // and so on the Categories...
    );
    

    And the processing of this array is somewhat the same, but note how foreach iterates $cat['Products']:

    foreach ($categories as $cname => $cat)
    {
        // here you raech the data of the category by $cat ...
    
        foreach ($cat['Products'] as $subcat)
        {
            // here you reach the data of the product by $subcat ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.