Home >php教程 >php手册 >怎样判断一个字符,在另一个字符串中,判断字符,字符串

怎样判断一个字符,在另一个字符串中,判断字符,字符串

WBOY
WBOYOriginal
2016-06-13 08:57:06842browse

怎样判断一个字符,在另一个字符串中,判断字符,字符串

应用场景:做修改操作时,做复选框的选中状态。

<span>//</span><span>字段存的是id值,如 7,8,9  这些id值是需要被选中的</span>

<span>$checkId</span> = '7,8,9'<span>;

被循环的id值

</span><span>$idAll</span> = <span>array</span>('1','2','3','5','7','8','9'<span>);

 // ',7,8,9,'   ',1,'

</span><span>foreach</span>(<span>$idAll</span> <span>as</span> <span>$k</span>=><span>$v</span><span>){

  </span><span>if</span>(<span>strpos</span>(','.<span>$checked</span>.',', ' ,  '.<span>$v</span>.','<span>) !== FALSE){

    </span><span>$check</span> = 'checked="checked"'<span>;

  }</span><span>else</span><span>{

    </span><span>$check</span> = ''<span>;

  }

}</span>

 

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