Collecting data from different positions in a given array I'm writing a PHP function to collect data from different positions in a given array.  I've done it as follows which gives me what I require. 

for ($a=9; $a &lt; 13; $a++) {
     $n = $arr[$a][2];
     $p = $arr[$a][3];
     $c = $p;
     $v1[] = array($n,$p,$c);
}

for ($b=3; $b &lt; 16; $b+=4) {
 $h = $arr[6][$b];  
     $m = $arr[5][$b]; 
     $l = $arr[4][$b];
     $v2[] = array($h,$m,$l);
}

foreach ($v1 as $k=&gt;$o) {
    $r[] = array( 'na'=&gt; $o[0], 'pr'=&gt; $o[1], 'cu' =&gt; $o[2], 'val1' =&gt; $v2[$k][0], 'val2' =&gt; $v2[$k][1], 'val3' =&gt; $v2[$k][2]);
}


To get the output in this format, without repeating the fields:

[0] = &gt; Array 
           [na] =&gt; Text 
           [pr] =&gt; 1
           [cu] =&gt; Text
           [val1] =&gt; 1
           [val2] =&gt; 2
           [val3] =&gt; 3

[1] = &gt; Array 
           ....
           ....

[3] = &gt; Array
           [na] =&gt; Text3 
           [pr] =&gt; 1-3
           [cu] =&gt; Text-22
           [val1] =&gt; 101
           [val2] =&gt; 22
           [val3] =&gt; 34


Is there a better, more efficient way to do this?
Should work (at least it doesn't look like a riddle anymore:)

for ($i = 0; $i &lt; 4; $i++) {
    $a = $i + 9;
    $b = 3 + $i * 4;

    $r[] = array(
        'na'   =&gt; $arr[$a][2],
        'pr'   =&gt; $arr[$a][3],
        'cu'   =&gt; $arr[$a][3],
        'val1' =&gt; $arr[6][$b],
        'val2' =&gt; $arr[5][$b],
        'val3' =&gt; $arr[4][$b]
    );
}


if $r[..]['cu'] is some function result assign to function call directly.