When I do the foreach loop for the print_r output I can succesfully output $key but when outputting $cats the output is 'array'. What index do I need to pass to the varibale $cats[??]. Do I need another foreach loop in View or do I need to reorganize the array in controller? (which I tried both without success). As you can tell I am not the master in programming. Thanks for your patience and any direction!
View:
<?php foreach($categories_sorted as $key => $cats) : ?>
<div class="box_container">
<div class="box_head"><?= $key; ?></div>
<div class="box_body"><?= $cats; ?></div>
</div>
<?php endforeach; ?>
Print_r:
Array
(
[Things to Do] => Array
(
[0] => Activities and Attractions
[1] => Castles
[2] => Golf
[3] => Islands and Beaches
[4] => Kids and Family
[5] => Landmarks and Architecture
[6] => Museums and Galleries
[7] => Nightlife
[8] => Parks and Gardens
[9] => Shopping
[10] => Sports and Outdoor
[11] => Tours Tracks and Cruises
[12] => Tracks and Trails
[13] => Wellness
)
[Transportation] => Array
(
[0] => Airport Transfers
[1] => Car Leasing
[2] => Flights
[3] => Public Transport
[4] => Taxis
[5] => Transport Lift Ride
[6] => Vehicle Rental
[7] => Vehicle Sales
)
)
Controller:
function categories(){
$this->load->model('array_model');
$category_row = $this->array_model->get_categories_all();
$arr_maincats = array();
foreach($category_row as $row){
if(!isset($arr_maincats[$row['category']]))
$maincats = $row['maincategory'];
$arr_maincats[$maincats][] = $row['category'];
}
$data['categories_sorted'] = $arr_maincats;
$this->load->view('array_view', $data);