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

WBOY
Release: 2016-06-13 11:56:48
Original
987 people have browsed it

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

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


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

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

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

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

------解决方案--------------------
估计是想把数字变成对应文字
<br /><?php<br />echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';<br /><br />$str ="3,8,9,10,11,";<br />$array = explode(",", $str);<br />foreach($array AS $_key=>$value){ <br />    echo show($value);<br />}<br /><br />function show($v){<br />    if($v==3){<br />        return '你好 ';<br />    }elseif($v==11){<br />        return '我好 ';<br />    }else{<br />        return '都好 ';<br />    }<br />}<br />?><br />
Copy after login

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

Related labels:
source:php.cn
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!