0
<?php
$a[0]["streamtitle"]= "SEM-VI";
$a[1]["streamtitle"]= "CE";
$a[2]["streamtitle"]= "B.E.";


$b[0]["streamtitle"] = "SEM-VI,CE,B.E.";
$b[1]["streamtitle"] = "SEM-VII,CE,B.E.";
$b[2]["streamtitle"] = "SEM-VIII,CE,B.E.";
$b[3]["streamtitle"] = "SEM-VI,EC,B.E.";
$b[4]["streamtitle"] = "SEM-VI,CE,B.E.";

$i=0;
for($i=0; $i<sizeof($b); $i++) {
    if (strstr($b[$i]["streamtitle"], $a[0]["streamtitle"]) && strstr($b[$i]["streamtitle"], $a[1]["streamtitle"]) && strstr($b[$i]["streamtitle"], $a[2]["streamtitle"]))
       print "found ".'</br>';
    else
       print "not found".'</br>';
}

?>

こんにちは、私は$aと同じ値を持つ配列$bから値をフィルタリングしています。上記のコードはしばらくは正常に機能していますが、SEM-Vを指定すると失敗します。私が取るとき

$a[0]["streamtitle"]= "SEM-V";
$a[1]["streamtitle"]= "CE";
$a[2]["streamtitle"]= "B.E.";

各文字列にはサブ文字列として「SEM-V」が含まれ、CE、BEも一般的であり、SEM-V、SEM-VI、SEM-VIIIなどであるため、$bの4つの要素に一致します。

「SEM-V」のみに一致するアイデアを提案してください。

4

1 に答える 1

1

If the format of the streamtitle always uses commas as the delimiter, you can match "SEM-V," instead of "SEM-V".

Other options include exploding the streamtitle and checking the different parts.

$parts = explode(",", $b[1]["streamtitle"]);
if($parts[0] == $a[0]["streamtitle"]
   && $parts[1] == $a[1]["streamtitle"]
   && $parts[2] == $a[2]["streamtitle"])
{
   print "found<br />";
}
else print "not fond<br />";
于 2012-04-08T06:56:13.630 に答える