如何在数组中保留n个值?

My data

1 : "aaa"
2 : "bbb"
2 : "ccc"
3 : "ddd"
4 : "eee"
4 : "fff"
4 : "ggg"

How could I keep these value in PHP array ? Are there any for-loop implementation example ?

[edited] How to make this array from my data via for-loop php ?

$array = array(
   1 => array("aaa"), 
   2 => array("bbb", "ccc"), 
   3 => array("ddd"),
   4 => array("eee", "fff", "ggg")
);

[edited#2] My real code:

$list = "SELECT.....";    
$root = retrieve($list);
// $root is a array of the data from PostgreSQL;
foreach($root as $i => $v){
    if(cond) {
        $q = "SELECT ...(use variables from $root)";
        $a = retrieve($q);  
        for($a as $j => $w) {
            echo $index." ".$v["aid"]." ".$w['new_geom']."<br />";
        }
        //what this line printed, i simplified to the sample data above
        $index++;           
    }   
} 

[edited#3] this is what it print

...
23 33 "aaa"
24 34 "bbb" 
25 34 "ccc" 
26 35 "ddd" 
...

I'm guessing this is what you want. I'm also guessing that $v['aid'] contains the index of the new array you want and that $w['new_geom'] contains the values, e.g.: aaa, bbb etc

$list = "SELECT.....";    
$root = retrieve($list);

$theNewArray = array();
foreach($root as $i => $v){
    if(cond) {
        $q = "SELECT ...(use variables from $root)";
        $a = retrieve($q);  
        for($a as $j => $w) {
            if (!array_key_exists($v["aid"], $theNewArray)) {
                $theNewArray[$v["aid"]] =  array();
            }

            $theNewArray[$v["aid"]][] = $w['new_geom'];

            echo $index." ".$v["aid"]." ".$w['new_geom']."<br />";
        }
        //what this line printed, i simplified to the sample data above
        $index++;           
    }   
}

It's pretty simple, just use nested foreach loop

$array = array(
   1 => array("aaa"), 
   2 => array("bbb", "ccc"), 
   3 => array("ddd"),
   4 => array("eee", "fff", "ggg")
);

foreach($array as $num => $array2) {
    foreach($array2 as $str) {
      echo "
".$num." : ".$str;
    }
}

Output:

1 : aaa
2 : bbb
2 : ccc
3 : ddd
4 : eee
4 : fff
4 : ggg