At the moment I have a single array made up of multiple other arrays ie:
-- Category
-- Subcategory
-- Name
-- Count
-- Subcategory
-- Name
-- Count
-- Subcategory
-- Name
-- Count
-- Category
-- Subcategory
-- Name
-- Count
-- Subcategory
-- Name
-- Count
This continues on for approximately 60 categories and approx 10 - 30 subcategories under each.
I want to display the categories & subcategories on a PHP/HTML page in a column format.
My understanding so far would be that I need to divide the total amount of categories by the columns required and then possibly use array_slice
or array_splice
to display the categories for each column.
So the formula for the amount of categories per column would be something like:
$categoriesPerColumn = ceil($TotalNumberOfCategories / $numberOfColumns);
By using columns I mean using <div>
tags with css formatting to seperate the columns ie:
-----------------------------------------------------------------------------
| First Category | Third Category |
| - Subcategory 1 (Count) | - Subcategory 1 |
| - Subcategory 2 (Count) | - Subcategory 2 |
| - Subcategory 3 (Count) | Fourth Category |
| - Subcategory 4 (Count) | - Subcategory 1 |
| Second Category | Fifth Category |
| - Subcategory 1 (Count) | - Subcategory 1 |
| - Subcategory 2 (Count) | - Subcategory 2 |
| - Subcategory 3 (Count) | - Subcategory 3 |
| - Subcategory 4 (Count) | - Subcategory 4 |
| | - Subcategory 5 |
-----------------------------------------------------------------------------
Questions:
- Is this the correct way of doing so?
- How can this be done in PHP?