我有一個數組:如何做計算在陣列中
Array
(
[0] => Array
(
[batch_id] => 1
[seq_id] => 1
[q_id] => 2046
[a1] => 0
[a2] => 1
[a3] => 2
[a4] => 3
[a5] => 4
)
)
我需要減去由1個
慾望結果的A1-A5的值(例如A1):
array(4) {
["w_id"]=>
string(5) "99911"
["q_id"]=>
string(4) "2046"
["c_id"]=>
string(6) "a1"
["rank"]=>
int(1) "-1"
}
我的代碼如下:
$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 => $v){
if(preg_match('{^a\d+$}',$k)){
$new_insert[] = array(
'w_id'=>$rid,
'q_id' =>$q_id,
'c_id' =>$k,
'rank'=>$v-1
);
}
}
Howeve R,排名的結果變成
array(4) {
["w_id"]=>
string(5) "99911"
["q_id"]=>
string(4) "2046"
["c_id"]=>
string(6) "a1"
["rank"]=>
int(0)
}
無法顯示排名
我的代碼的任何問題的價值?誰能回答我的問題非常感謝你
爲什麼這個標記爲'mysql'? – Aquillo 2013-05-10 09:14:59
什麼是$ cr初始化? – simpleuser 2013-05-10 09:15:54
這沒有任何意義.. – billyonecan 2013-05-10 09:16:32