php使用array_map迭代multidimesional数组

时间:2016-03-23 13:53:39

标签: php arrays laravel

我有一个数组如下:

array:4 [
  "tag" => "form"
  "attr" => array:1 [
    "class" => array:1 [
      0 => "form-horizontal"
    ]
  ]
  "text" => "  "
  "child" => array:1 [
    0 => array:3 [
      "tag" => "fieldset"
      "text" => "   "
      "child" => array:1 [
        0 => array:2 [
          "tag" => "input"
          "text" => "input name"
        ]
      ]
    ]
  ]
]

id喜欢重新创建一个新数组,如下所示

array[
 0 => array[
     "input" => "something",
     "value" => "somevalue"
   ],
0 => array[
     "input" => "something",
     "value" => "somevalue"
   ]
]

if" tag" => "输入"

目前正在使用以下代码,基于laravel:

 public function AjaxData(Request $request)
    {
        //

        $array = $request->json;
        debug($array);


        $array2 = array_map(array($this, 'sanitize'), $test1 );


        debug($array2);
        return response()->json(['name' => $array['tag'] ]);

    }

     private function sanitize($value)
    {

        return  $value['tag'];
    }

0 个答案:

没有答案