php version of pythons if in -
python has great: if sub-string in string, this:
if "fox" in "the quick brown fox jumps on lazy dog": print true
does php have equivalent this?
if(stripos("the quick brown fox jumps on lazy dog","fox")!==false) { echo 'true'; }
stripos , strpos return position @ match started, need use strict comparison (=== or !==) avoid false negative when needle @ pos. 0 in haystack.
you may prefer stristr, returns matched string or boolean false.
in_array works same in
in python lists , dictionaries, if thinking beyond strings.
Comments
Post a Comment