0

I have a list of groups in a SQL query and would like them to be output to an array so that it can be referenced later on.

Currently I have the following code which loops through the groups and puts them in to the $test_array:

$test_array = array();
$query = $this->site_model->list_groups();
foreach($query as $r1) :
    $test_array[] = $r1->group_name;
endforeach;

This shows the following array:

Array
(
    [0] => Group 1
    [1] => Group 2
    [2] => Group 3
    [3] => Group 4
    [4] => Group 5
    [5] => Group 6
    [6] => Group 7
    [7] => Group 8
)

What I would like is for the same query to pass to an array like below, with the intention of adding other segments to the array later on:

Array
(
    [Round 1] => Array
    (
        [0] => Group 1
        [1] => Group 2
        [2] => Group 3
        [3] => Group 4
        [4] => Group 5
        [5] => Group 6
        [6] => Group 7
        [7] => Group 8
    )
)

Is this possible?

1 Answer 1

2
$test_array = array('Round 1' => array());
...
$test_array['Round 1'][] = $r1->group_name;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.