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

时间:2015-09-10 06:32:43

标签: php arrays

我跟随数组:

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。如何在元素较少的情况下取消设置数组索引?

1 个答案:

答案 0 :(得分:6)

您可以在此处使用array_filter作为

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