How to find elements in array that contain a given substring?

后端 未结 4 2016
礼貌的吻别
礼貌的吻别 2020-12-21 12:02

I have 3 strings, I would like to get only the equal strings of them, something like this:

$Var1 = \"Sant\";
$Array[] = \"Hello Santa Claus\";   // Name_1
$A         


        
4条回答
  •  臣服心动
    2020-12-21 12:41

    you can use strpos() function of php to identify if a string consist a substring or not as

    $a = 'Sant';
    foreach($Array as $name) 
    {
        if (strpos($name, $a) !== false) {
            echo $name;
        }
    }
    

提交回复
热议问题