猿问

如果多维数组PHP中的另一个数组获取了所有键,如何删除数组

你能帮我解决这个问题吗?在 PHP 中删除第 4 个和第 5 个数组的函数是什么。


Array

(

    [0] => Array

        (

            [10] => 98

            [11] => 1

            [433438] => 8

        )


    [1] => Array

        (

            [10] => 98

            [11] => 1

            [433438] => 1

        )


    [2] => Array

        (

            [13] => 98

            [11] => 2

            [433438] => 8

        )


    [3] => Array

        (

            [14] => 98

            [11] => 2

            [433438] => 1

        )


    [4] => Array

        (

            [10] => 18

            [11] => 1

        )


    [5] => Array

        (

            [14] => 18

            [11] => 2

        )


)

提前致谢。


一只萌萌小番薯
浏览 103回答 2
2回答

30秒到达战场

$base = [&nbsp; &nbsp; [10 => 98, 11 => 1, 433438 => 8],&nbsp; &nbsp; [10 => 98, 11 => 1, 433438 => 1],&nbsp; &nbsp; [13 => 98, 11 => 2, 433438 => 8],&nbsp; &nbsp; [14 => 98, 11 => 2, 433438 => 1],&nbsp; &nbsp; [10 => 18, 11 => 1],&nbsp; &nbsp; [14 => 18, 11 => 2],];$invalid = [];for ($i = 0; $i <= count($base) - 1; $i++) {&nbsp; &nbsp; for ($j = 0; $j <= count($base) - 1; $j++) {&nbsp; &nbsp; &nbsp; &nbsp; $refCount = count($base[$j]);&nbsp; &nbsp; &nbsp; &nbsp; $interSectCount = count(array_intersect(array_keys($base[$i]), array_keys($base[$j])));&nbsp; &nbsp; &nbsp; &nbsp; if (count($base[$i]) !== $refCount && $interSectCount === $refCount) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $invalid[] = $j;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}foreach ($invalid as $item) {&nbsp; &nbsp; unset($base[$item]);}

喵喵时光机

您可以使用array_pop()消除数组最后一个元素的函数,但如果您使用它两次,您将获得所需的结果<?php$data&nbsp; = [&nbsp; &nbsp; 1 => [1,2],&nbsp; &nbsp; 2 => [1,3],&nbsp; &nbsp; 3 => [1,4]];$value = array_pop($data);$value = array_pop($data);?>输出Array(&nbsp; &nbsp; [1] => Array&nbsp; &nbsp; &nbsp; &nbsp; (&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [0] => 1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [1] => 2&nbsp; &nbsp; &nbsp; &nbsp; ))
随时随地看视频慕课网APP
我要回答