Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.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 - Fatal编程技术网

Php 如果长度小于,则取消设置数组元素

Php 如果长度小于,则取消设置数组元素,php,arrays,Php,Arrays,我有以下数组: Array ( [1] => Array ( [team1_id] => 2 [agegroup_id] => 18 [team2_id] => 3 [team_ground] => Adeilade [matchdate] => 2016-04-01 [matchtime] =

我有以下数组:

Array
(
    [1] => Array
        (
            [team1_id] => 2
            [agegroup_id] => 18
            [team2_id] => 3
            [team_ground] => Adeilade
            [matchdate] => 2016-04-01
            [matchtime] => 9:00 AM
        )

    [2] => Array
        (
            [team1_id] => 3
            [agegroup_id] => 18
            [team2_id] => 2
            [team_ground] => Adeilade
            [matchdate] => 2016-04-13
            [matchtime] => 10:00 AM
        )

    [3] => Array
        (
            [team1_id] => 2
            [agegroup_id] => 18
            [team2_id] => 3
            [team_ground] => Adeilade
            [matchdate] => 2016-04-20
            [matchtime] => 2:00 PM
        )

    [4] => Array
        (
            [team1_id] => 3
            [agegroup_id] => 18
            [team2_id] => 2
            [team_ground] => Adeilade
            [matchdate] => 04/07/2016
            [matchtime] => 5:00 PM
        )

    [6] => Array
        (
            [team1_id] => 9
            [agegroup_id] => 36
            [team2_id] => 4
            [team_ground] => Motera Stadium
            [matchdate] => 2016-04-13
            [matchtime] => 9:00 AM
        )

    [7] => Array
        (
            [team1_id] => 4
            [agegroup_id] => 36
            [team2_id] => 9
            [team_ground] => Motera Stadium
            [matchdate] => 2016-04-13
            [matchtime] => 5:00 PM
        )

    [9] => Array
        (
            [team1_id] => 1
            [agegroup_id] => 37
            [team2_id] => 8
            [team_ground] => Eden Garden
            [matchdate] => 2016-04-18
            [matchtime] => 7:00 PM
        )

    [10] => Array
        (
            [team1_id] => 8
            [agegroup_id] => 37
            [team2_id] => 1
            [team_ground] => Eden Garden
            [matchdate] => 2016-04-25
            [matchtime] => 8:00 PM
        )

    [11] => Array
        (
            [team1_id] => 1
            [agegroup_id] => 37
            [team2_id] => 8
            [team_ground] => Eden Garden
            [matchdate] => 04/26/2016
            [matchtime] => 8:00 PM
        )

    [0] => Array
        (
            [agegroup_id] => 18
        )

    [5] => Array
        (
            [agegroup_id] => 36
        )

    [8] => Array
        (
            [agegroup_id] => 37
        )

)
若数组只有一个元素,那个么我必须取消设置它。在本例中,我想在PHP中取消设置数组索引0,5,8。当数组的元素较少时,如何取消设置数组索引?

您只需使用此处的数组过滤器即可

$result = array_filter($your_array,function($v){ return count($v) > 1;});
print_r($result);

您还可以使用简单的foreach:

foreach ($array as $key => $value)
  {
     if(sizeOf($array[$key]) < 2)
         unset($array[$key]);
  }  

这是一张有效的

感谢您的快速回复,但钥匙没有固定。这是动态排列谢谢你的回复,但内河的回答解决了我的问题。谢谢您的时间和合作。@TaniPartner没问题