比较PHP中的值或字符串[重复]

This question already has an answer here:

I need to compare whether (1) contains (2).From the example below (2) 1,2,3,4,5,6,7,8,18 are existed in (1).How can I check with the same in PHP

(1)1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25            
(2)1,2,3,4,5,6,7,8,18
</div>
$array1 = explode(',', $var1);
$array2 = explode(',', $var2);

$diff = array_diff($array2, $array1);
// return !count($diff);

Explode the strings in to arrays then use array_diff.

$diff will contain an array of items from $array2 not present in $array1. If this array is empty, this means all the items exist in $array1.

You could also use array_intersect to see if the returned array is equal to array2:

$intersect = array_intersect($array2, $array1);
// return $array2 == $insersect;