将数组分解与字符串进行比较


Compare an array explode with a string

我需要一些帮助来解决这个问题。我有一个这样的数组:

$asd = explode(",", "1, 5, 6, 8, 10");

我想用字符串比较$asd:

if($asd == '8') {
    //something
} else {
    //something
}

我无法比较它们。

您无法将数组与字符串进行比较。您需要迭代数组的元素。喜欢这个:

foreach ($asd as $k)
{
    if ($k == '8') echo "ok";
}