應用場景:做修改操作時,做複選框的選取狀態。
<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>
以上就介紹了怎樣判斷一個字符,在另一個字符串中,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。