php Cannot call the function for array_map -


i using php 5.2.10 want array_map on array , created function array mapping

function get_result(){     $result = mysql_query("select * table");     while($cr = mysql_fetch_array($result)){         $b = array_map(`calc`,$cr);         $rr_id = $cr['batch_id'].$cr['seq_id'];   $mqrrid = '999'.$rr_id;   $question_id = $cr['question_id'];         foreach ($b $k => $v){             if(preg_match('{^item \d+$}',$k)){                 $new_insert[] = array(                     'r_id'=>$mqrrid,                     'q_id' =>$q_id,                     'c_id' =>$k,                     'rank'=>$v                 );             }         }     } }     function calc($n){     foreach($n $m=> &$x) {         if (preg_match('{^item \d+$}', $m)) {             if($x == null){                 $x = $x;             }else {                 $x = $x - 1;             }         }     }        return $n; } 

i don't know why cannot call function calc in array_map.....i cannot figure out reason..... can me ?

original array :( output after array_map(calc,$cr) same follow)

array(23) { ["batch_id"]=> string(1) "1" ["seq_id"]=> string(1) "1" ["question_id"]=> string(4) "2086" ["item 1"]=> string(1) "1" ["item 2"]=> string(1) "2" ["item 3"]=> string(1) "3" ["item 4"]=> string(1) "4" ["item 5"]=> string(1) "5" ["item 6"]=> null 

what need : (minus value of item 1 6 1, if null leave ~)

array(23) { ["batch_id"]=> string(1) "1" ["seq_id"]=> string(1) "1" ["q_id"]=> string(4) "2086" ["item 1"]=> string(1) "0" ["item 2"]=> string(1) "1" ["item 3"]=> string(1) "2" ["item 4"]=> string(1) "3" ["item 5"]=> string(1) "4" ["item 6"]=> null 

finally, result become this:(example of item 1 , item 6)

 array(4) { ["r_id"]=> string(5) "99911" ["q_id"]=> string(4) "2086" ["c_id"]=> string(6) "item 1" ["rank"]=> string(1) "0" } array(4) { ["r_id"]=> string(5) "99916" ["q_id"]=> string(4) "2086" ["c_id"]=> string(6) "item 6" ["rank"]=> string(4) null } 

i think don't have prepare function array_map.

function get_result($link_identifier = null) {     $result = mysql_query('select * table', $link_identifier);     $new = array();     while ($rows = mysql_fetch_assoc($result)) {         $r_id = '999' . $rows['batch_id'] . $rows['seq_id'];         foreach ($rows $k => $v) {             if ($v !== null && preg_match('@^item \\d+$@', $k)) {                 $v = (string)((int)$v + 1);             }             $new[] = array(                 'r_id' => $r_id,                 'q_id' => $rows['question_id'],                 'c_id' => $k,                 'rank' => $v,             );         }     }     return $new; } 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -