过滤多数组

时间:2018-10-12 13:52:37

标签: php arrays filter

我要过滤此数组并获取[1] => 1的所有数组。因此,php代码必须返回数组[1],[2]和[4]。我不知道该怎么做,所以我将不胜感激。

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 1
            [2] => data1
        )
    [1] => Array
        (
            [0] => 2
            [1] => 1
            [2] => data2
        )
    [2] => Array
        (
            [0] => 3
            [1] => 2
            [2] => data3
        )
    [3] => Array
        (
            [0] => 4
            [1] => 2
            [2] => data4
        )
    [4] => Array
        (
            [0] => 5
            [1] => 1
            [2] => data5
        )
    [5] => Array
        (
            [0] => 6
            [1] => 3
            [2] => data6
        )
)

2 个答案:

答案 0 :(得分:0)

使用简单的foreach循环并在项目与所需的项匹配时附加到新数组将起作用:

{
     "name": "Python: Debug Console",
     "type": "python",
     "request": "launch",
     "program": "${file}",
     "console": "none"
}

答案 1 :(得分:0)

假设您的父数组名为$ master:

foreach ($master as $m)
{
  if ($m[1] != 1)
  {
    unset($m);
  }
}

return $master;