0

I'am stuck and didn't found any tutorial or examples on how to produce the multidimensional array like this while using foreach():

'0' => '-- ALL --',
'CATEGORY 1' => array(
    '11'  => 'Item 11',
    '12'  => 'Item 12',
    '13'  => 'Item 13',
),
'CATEGORY 2' => array(
    '14'  => 'Item 14',
    '15'  => 'Item 15',
    '16'  => 'Item 16',
)

And this is where I'am stucked:

$items = $this->model->get_categories();

foreach($items as $item){

    $result[$item->title] = array();

    // HOW TO CONTINUE NEXT ? :(

}
0

2 Answers 2

1

Something like

$items = $this->model->get_categories();

foreach($items as $item){

    $result[$item->title] = array();

    foreach($item->data as $key => $data){ //replace $item->data with whatever your second level stuff is
        $result[$item->title][$key] = $data;
    }

}
Sign up to request clarification or add additional context in comments.

Comments

1

Assuming the value is in $item->value:

$result[$item->title][] = $item->value;

will append $item->value to your array.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.