PHP用for循环遍历数组,如何能把数组中所有的2变成红色?代码如下: $a = array(1,
答案:2 悬赏:50 手机版
解决时间 2021-11-08 08:20
- 提问者网友:我是女神我骄傲
- 2021-11-07 12:12
PHP用for循环遍历数组,如何能把数组中所有的2变成红色?代码如下: $a = array(1,
最佳答案
- 五星知识达人网友:低音帝王
- 2021-11-07 13:23
$a = array(1,2,3,2,4,5,2,3,2,3,4,1,2,3,4,2,3,4,8,2,3,8,7,4,6,1,2,4,1,2,3,4,8,7,1,6,2,3,9,4,8,1,2,3,4,9,1,8,2,3,4,9,8,1,2,6,3,4,1,2,3,4,1);
for($i=0;$i if($a[$i]==2){
echo "".$a[$i].",";
}else{
echo "".$a[$i].",";
}
}
?>给他加一个标签,然后设置color颜色就可以了,结果如下:
操作数据推荐用:foreach();
$a = array(1,2,3,2,4,5,2,3,2,3,4,1,2,3,4,2,3,4,8,2,3,8,7,4,6,1,2,4,1,2,3,4,8,7,1,6,2,3,9,4,8,1,2,3,4,9,1,8,2,3,4,9,8,1,2,6,3,4,1,2,3,4,1);
foreach($a as $k){
if($k==2){
echo "".$k.",";
}else{
echo "".$k.",";
}
}
?>
for($i=0;$i
echo "".$a[$i].",";
}else{
echo "".$a[$i].",";
}
}
?>给他加一个标签,然后设置color颜色就可以了,结果如下:
操作数据推荐用:foreach();
$a = array(1,2,3,2,4,5,2,3,2,3,4,1,2,3,4,2,3,4,8,2,3,8,7,4,6,1,2,4,1,2,3,4,8,7,1,6,2,3,9,4,8,1,2,3,4,9,1,8,2,3,4,9,8,1,2,6,3,4,1,2,3,4,1);
foreach($a as $k){
if($k==2){
echo "".$k.",";
}else{
echo "".$k.",";
}
}
?>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯