2 回答
TA贡献1780条经验 获得超1个赞
循环并$arr2检查strpos():$arr1["folds"]
<?php
$arr1 = ["folds" => '02,04'];
$arr2 = [
["Offer" => "Website", "folds" => '02'],
["Offer" => "Development", "folds" => '02,04,09']
];
$arr3 = [];
foreach($arr2 as $i_arr){
if(isset($i_arr["folds"]) && strpos($i_arr["folds"], $arr1["folds"]) > -1){
$arr3[] = $i_arr;
}
}
print_r($arr3);
?>
输出:
Array
(
[0] => Array
(
[Offer] => Development
[folds] => 02,04,09
)
)
https://paiza.io/projects/_0nC44WHlZJpkdLOjm1Tkw
TA贡献1794条经验 获得超7个赞
这里的解决方案 - 也许它会帮助别人:
<?php
// Your code here!
$arr1 = ["folds" => '01,03,'];
if($arr1['folds'][strlen($arr1['folds'])-1] == ","){
$arr1['folds'] = substr($arr1['folds'], 0, -1);
}
$check = explode(",", $arr1['folds']);
$arr2 = [
["Offer" => "Website", "folds" => '03'],
["Offer" => "Development", "folds" => '01,03,05,10,14,15,21,22,'],
["Offer" => "Testing", "folds" => '01,03,04,10,15,22'],
["Offer" => "Sales", "folds" => '01,03,10,22,']
];
$use = "no";
$arr3 = [];
foreach($arr2 as $i_arr){
if($i_arr['folds'][strlen($i_arr['folds'])-1] == ","){
$i_arr['folds'] = substr($i_arr['folds'], 0, -1);
}
$tocheck = explode(",", $i_arr['folds']);
foreach($check as $chk){
if(in_array($chk, $tocheck)){
$use = "yes";
} else {
$use = "no";
break;
}
}
if($use == "yes"){
$arr3[] = $i_arr;
}
}
print_r($arr3);
?>
- 2 回答
- 0 关注
- 107 浏览
添加回答
举报