Home > Backend Development > PHP Tutorial > 一个循环判断进入了误区 请求指导

一个循环判断进入了误区 请求指导

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:57:17
Original
799 people have browsed it

<?php$str ="3,8,9,10,11,";$array = explode(",", $str);foreach($array AS $_key=>$value){  $show.="$value";}if($show==3){		echo "你好";}elseif($show==11){	echo "我好";	}else{		echo "都好";}
Copy after login


$str ="3,8,9,10,11,"; 中的 3 8 9 10 11 的位置是不确定的 也就是会变化的

$show==3 中的3 就是上面的数字 也就是说是根据$str 进行分割后的值进行判断的

好像迷糊了 一直无法进行判断


回复讨论(解决方案)

$str ="3,8,9,10,11,";$array = explode(",", $str);foreach($array AS $_key=>$value){   if($value==3){     echo "你好";  }elseif($value==11){     echo "我好";     }else{    echo "都好";  }}
Copy after login

$show.="$value";这个你做甚?

你这是要干啥子啊 分了又连上 是要去掉, 号??

详细描述一下你的需求,期望得到什么结果。

估计是想把数字变成对应文字

<?phpecho '<meta http-equiv="content-type" content="text/html;charset=utf-8">';$str ="3,8,9,10,11,";$array = explode(",", $str);foreach($array AS $_key=>$value){     echo show($value);}function show($v){    if($v==3){        return '你好 ';    }elseif($v==11){        return '我好 ';    }else{        return '都好 ';    }}?>
Copy after login

你好 都好 都好 都好 我好 都好

感谢各位的回答 家里有事走了几天 

具体的就是  一个循环 里面有个字段是存在的是  3,8,9,10,11 类型的  但是要判断这个

大循环里面的字段判断 5楼是正确的

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template