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 關注
- 156 瀏覽
添加回答
舉報