0

我在 SQL 查询中有一个组列表,并希望将它们输出到一个数组中,以便以后可以引用它。

目前我有以下代码循环遍历组并将它们放入$test_array

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

这显示了以下数组:

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
)

我想要将相同的查询传递给如下所示的数组,以便稍后将其他段添加到数组中:

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
    )
)

这可能吗?

4

1 回答 1

2
$test_array = array('Round 1' => array());
...
$test_array['Round 1'][] = $r1->group_name;
于 2012-06-20T22:21:08.110 回答