2 回答
TA贡献1828条经验 获得超6个赞
$base = [
[10 => 98, 11 => 1, 433438 => 8],
[10 => 98, 11 => 1, 433438 => 1],
[13 => 98, 11 => 2, 433438 => 8],
[14 => 98, 11 => 2, 433438 => 1],
[10 => 18, 11 => 1],
[14 => 18, 11 => 2],
];
$invalid = [];
for ($i = 0; $i <= count($base) - 1; $i++) {
for ($j = 0; $j <= count($base) - 1; $j++) {
$refCount = count($base[$j]);
$interSectCount = count(array_intersect(array_keys($base[$i]), array_keys($base[$j])));
if (count($base[$i]) !== $refCount && $interSectCount === $refCount) {
$invalid[] = $j;
}
}
}
foreach ($invalid as $item) {
unset($base[$item]);
}
TA贡献1846条经验 获得超7个赞
您可以使用array_pop()消除数组最后一个元素的函数,但如果您使用它两次,您将获得所需的结果
<?php
$data = [
1 => [1,2],
2 => [1,3],
3 => [1,4]
];
$value = array_pop($data);
$value = array_pop($data);
?>
输出
Array
(
[1] => Array
(
[0] => 1
[1] => 2
)
)
- 2 回答
- 0 关注
- 102 浏览
添加回答
举报