dsfhe34889
2019-02-06 10:51
浏览 47
已采纳

大于或小于array_walk递归

I am trying to replace array value with specific condition.

Suppose array $mark has following value

$mark = array(90,85);

Just normal checking value it is echoing correct value

array_walk_recursive($mark, function (&$k) { 
  if($k==90){$k='4.0';}
  if($k==85){$k='3.6';}
});

print_r($mark);

Output is

Array ( [0] => 4.0 [1] => 3.6 )

But while applying condition such as greater than or less than, it returns wrong value.

array_walk_recursive($mark, function (&$k) { 
  if($k>=90){$k='4.0';}
  if($k>=80 AND $k<90){$k='3.6';}
  if($k<79){$k='2.8';}
});

print_r($mark);

And the Output is

Array ( [0] => 2.8 [1] => 2.8 )
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题