how to do the calculation in an array
<p>I have an array : </p>

<pre><code>Array
(
    [0] =&gt; Array
  (
      [batch_id] =&gt; 1
      [seq_id] =&gt; 1
      [q_id] =&gt; 2046
      [a1] =&gt; 0
      [a2] =&gt; 1
      [a3] =&gt; 2
      [a4] =&gt; 3
      [a5] =&gt; 4

  )
)
</code></pre>

<p>I need to minus the value of a1-a5 by 1 </p>

<p>desire result(e.g. a1):</p>

<pre><code> array(4) {
["w_id"]=&gt;
string(5) "99911"
["q_id"]=&gt;
string(4) "2046"
["c_id"]=&gt;
string(6) "a1"
["rank"]=&gt;
int(1) "-1"
}
</code></pre>

<p>My code is as follow: </p>

<pre><code>$result = mysql_query("Select * from table_1");     
while($cr = mysql_fetch_array($result)){    
    $rr_id = $cr['batch_id'].$cr['seq_id'];
    $rid = '999'.$rr_id;
          $q_id = $cr['q_id'];
     foreach ($cr as $k =&gt; $v){
  if(preg_match('{^a\d+$}',$k)){
    $new_insert[] = array(
        'w_id'=&gt;$rid,
        'q_id' =&gt;$q_id,
        'c_id' =&gt;$k,
        'rank'=&gt;$v-1
);
     }
  }
</code></pre>

<p>However, the result of rank becomes</p>

<pre><code>array(4) {
["w_id"]=&gt;
string(5) "99911"
["q_id"]=&gt;
string(4) "2046"
["c_id"]=&gt;
string(6) "a1"
["rank"]=&gt;
int(0)
}
</code></pre>

<p>Cannot show the value of rank </p>

<p>Any problem with my code??Can someone answer my question thank you very much</p>
