Home > Backend Development > PHP Tutorial > How to determine a character in another string, determine the character, string_PHP tutorial

How to determine a character in another string, determine the character, string_PHP tutorial

WBOY
Release: 2016-07-13 09:45:36
Original
1150 people have browsed it

How to judge a character in another string, string

Application scenario: When making modification operations, check the selected state of the check box.

<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>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1040152.htmlTechArticleHow to judge a character in another string, string application scenario: when doing modification operations , to make the check box selected. // The field stores the id value, such as 7,8,9 this...
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