How to match whether a string is consistent / exists from an array

such as the question, I have tried it with my own ideas, but I can"t match

.
$Str = "Players";

$CotentCate = "UserOS|UserIP|UserLang|UserLocation|Players|JavaVersion|MCVersion|ServerCore|ServerSystem";

$content = trim($Str);
        $CotentArr = explode("|", $CotentCate);
        for ($i = 0; $i < count($CotentArr); $iPP) {
            if ($CotentArr[$i] == "") {
                continue;  
            }
            if (strpos($content, trim($CotentArr[$i])) != false) {
                die("true");
            }
        }
        die("false");

destination returns true

actually return false

Php
Jun.08,2021

$rr = substr_count($CotentCate,$Str);
echo $rr;

I think the method of Snow Prayer is very good
but for your code, why it doesn't match, I think the reason is here:

if (strpos($content, trim($CotentArr[$i])) != false)
The sentence ! = should be replaced with ! =
because the strpos function is used to find the string, and if found, the position where the string appears is returned. When the value of CotentArr [$I] is Players , its position in $content is 0 , after = .

digression:
is not recommended in for (expression 1; expression 2; Expression 3) expression 2 in uses the count function, because the three expressions are executed in the following order:
expression 1-> expression 2-> expression 3-> expression 3-> expression 2. the count function you use calculates the number of elements in the array multiple times. Of course, PHP is very fast, and you can not care about

.

helpless ~ No one uses in_array () ?

Menu