2 回答
TA贡献1797条经验 获得超6个赞
您的代码非常接近。您还需要explode
中的磁盘 ID 列表$st_data
,然后用于array_diff
检查该列表中是否存在所有值$rc_disk_ids
:
foreach($st_array as $st_data) {
$rc_disk_ids = explode(",",$rc_disk_id);
$st_disk_ids = explode(',', $st_data['disk']);
$match = array_diff($rc_disk_ids, $st_disk_ids);
if (empty($match)) {
echo "\nFound\n";
print_r($st_data);
}
else {
echo "Nope!";
}
}
样本数据的输出:
Found
Array
(
[id] => 1
[title] => Jane doe
[disk] => 1,3,2
)
Found
Array
(
[id] => 2
[title] => Jane Smith
[disk] => 3,1,4
)
TA贡献1843条经验 获得超7个赞
也许您可以尝试搜索字符串而不是比较数组。
$strArr = explode(",", "1,3");
$arrToBeSearched = ["1", "3", "2"];
foreach($strArr as $val){
if(!in_array($val, $arrToBeSearched)){
return FALSE;
}
}
// If it reaches here, then all values in
//the $strArr where found in the
//$arrToBeSearched
return TRUE;
- 2 回答
- 0 关注
- 126 浏览
添加回答
举报