Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从缺少列的数组中删除行_Php_Arrays_Filter - Fatal编程技术网

Php 如何从缺少列的数组中删除行

Php 如何从缺少列的数组中删除行,php,arrays,filter,Php,Arrays,Filter,好的。。。所以,我有一个系统,它为我提供了一系列的项目。这些项目如下所示: Array ( [1] => Array ( [protocol] => ip [dst-address] => 10.0.0.1 [tx] => 0 [rx] => 0 [tx-packets] => 0 [rx-pa

好的。。。所以,我有一个系统,它为我提供了一系列的项目。这些项目如下所示:

Array
(
    [1] => Array
        (
            [protocol] => ip
            [dst-address] => 10.0.0.1
            [tx] => 0
            [rx] => 0
            [tx-packets] => 0
            [rx-packets] => 0
        )

    [2] => Array
        (
            [protocol] => ip
            [dst-address] => 10.0.0.112
            [tx] => 0
            [rx] => 0
            [tx-packets] => 0
            [rx-packets] => 0
        )

    [3] => Array
        (
            [protocol] => ip
            [dst-address] => 10.0.0.130
            [tx] => 0
            [rx] => 0
            [tx-packets] => 0
            [rx-packets] => 0
        )

    [4] => Array
        (
            [tx] => 0
            [rx] => 0
            [tx-packets] => 0
            [rx-packets] => 0
        )

    [5] => Array
        (
            [protocol] => ip
            [dst-address] => 10.0.0.5
            [tx] => 0
            [rx] => 496
            [tx-packets] => 0
            [rx-packets] => 1
        )

    [6] => Array
        (
            [protocol] => ip
            [dst-address] => 10.0.0.6
            [tx] => 0
            [rx] => 528
            [tx-packets] => 0
            [rx-packets] => 1
        )

    [7] => Array
        (
            [protocol] => ip
            [dst-address] => 10.0.0.16
            [tx] => 624
            [rx] => 0
            [tx-packets] => 1
            [rx-packets] => 0
        )

    [8] => Array
        (
            [protocol] => ip
            [dst-address] => 10.0.0.24
            [tx] => 0
            [rx] => 448
            [tx-packets] => 0
            [rx-packets] => 1
        )

    [9] => Array
        (
            [protocol] => ip
            [dst-address] => 10.0.0.31
            [tx] => 0
            [rx] => 528
            [tx-packets] => 0
            [rx-packets] => 1
        )

    [10] => Array
        (
            [protocol] => ip
            [dst-address] => 10.0.0.44
            [tx] => 10592
            [rx] => 13200
            [tx-packets] => 20
            [rx-packets] => 28
        )
您是否看到,条目ID 4缺少表中的一些列

在PHP中,如何从数组中删除错误的行? 我希望正确修复阵列,以便对其重新排序以显示以下内容: -顶级tx -顶级rx -顶级发送数据包 -顶级接收数据包 -具有最多tx或rx或tx数据包或rx数据包的dst地址是什么

有关信息,此数组为dinamic。我的PHP代码将在while(true)循环(无数据存储)上从设备(路由器)获取它

这将在数组中循环,计算子数组的项数是否正确,如果没有,则删除它们。索引在每次传递时递增1,因此我们知道在何处删除不正确的子数组


您可以将计数更改为正确的项数。

您需要自己编写代码。如果您有问题,请发布您尝试过的内容,并清楚解释哪些内容不起作用,然后提供。读一个好问题。一定要阅读,这正是我要找的。它解决了我的问题。谢谢
$arrayVar = []; // Replace with your outter array;
$correctCount = 6;
$index = 0;
foreach($arrayVar as $subArray) {
  if(count($subArray) !== $correctCount) {
    unset($arrayVar[$index];
  }
  $index++;
}