开发者

isnt there a simple if condition to compre two arrays

so there are these two arrays:

$one = array("engineering", "applied", "mathematics");
$se = "Applied mathematics is a branch of mathematics that concerns itself with mathematical methods that are typically used in science, engineering, business, and industry.";
$two = explode(' ', $se);

if (//those 3 values from $one exist in $two开发者_StackOverflow) {
echo "i got it!";
} else {
echo "you dint get :(";
}

I was researching whit this but i did not find any simple answer. Can you help me?


You could use array_intersect to check if the values in one exist in two, if you get the same array back as a result you know they are in both.


Try array_intersect:

if ( array_intersect( $one, $two ) ) {
    // arrays share one or more terms
}

You should probably strtolower($se), since the intersect test is ===.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜