Home  >  Article  >  Backend Development  >  in_array变量赋值被当成一个值,求解决办法

in_array变量赋值被当成一个值,求解决办法

WBOY
WBOYOriginal
2016-06-13 12:39:57955browse

in_array变量赋值被当成一个值,求解决方法
in_array变量赋值被当成一个值,求解决方法
具体请看以下代码:

<br />
<?php<br />
//$meb['learned']数据库取值为:排舞,街舞,主持人,讲师<br />
$learn = explode(',',$meb['learned']);<br />
//echo $learn[0].$learn[1].$learn[2].$learn[3].$learn[4].$learn[5];<br />
$strp = str_replace(',', '", "', $meb['learned']);<br />
$strp2 = '"'.$strp.'"';<br />
$people = array($strp2);<br />
print_r($people); <br />
//以上输出结果为 Array ( [0] => "排舞", "街舞", "主持人", "讲师" ) <br />
if (in_array('讲师',$people)){<br />
echo "Match found";<br />
}<br />
else<br />
{<br />
echo "Match not found";<br />
}<br />
?><br />

in_array的判断结果输出为"Match not found",也即是说讲师没包含在$people中,可能原因是被当成一个整体。具体求解决方案,代码该如何优化下

Statement:
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