以下是两个字符串变量。如何检查$str2
包含$str1
的所有值?
$str1 = ',2,4,13,11,';
$str2 = ',1,2,22,20,6,4,21,18,4.146,11,1.124,13,';
我知道使用循环可能可以,但我想知道这是直接或不可能的吗?
带有array_diff
和explode
功能:
$str1 = ',2,4,13,11,';
$str2 = ',1,2,22,20,6,4,21,18,4.146,11,1.124,13,';
$contains_all = ! array_diff(explode(',', trim($str1,',')), explode(',', trim($str2,',')));
var_dump($contains_all); // true
类似的东西?
<?php
$str1 = ',2,4,13,11';
$str2 = ',1,2,22,20,6,4,21,18,4.146,11,1.124,13,';
$arr1 = explode(",",$str1);
$arr2 = explode(",",$str2);
$subArray = count(array_intersect($arr1 , $arr2)) == count($arr1);
if($subArray) {
echo 'TRUE';
} else {
echo 'FALSE';
}
?>