Php 删除中间阵列的更优雅的方法?

Php 删除中间阵列的更优雅的方法?,php,arrays,Php,Arrays,因此,我们拥有这个“美丽”的多维数组: array 0 => array 0 => object(SimpleXMLElement) public 'name' => string 'some name' public 'model' => string 'some model' 1 => object(SimpleXMLElement)

因此,我们拥有这个“美丽”的多维数组:

array 
  0 => 
    array 
      0 => 
        object(SimpleXMLElement)
          public 'name' => string 'some name'
          public 'model' => string 'some model'
      1 => 
        object(SimpleXMLElement)
          public 'name' => string 'some name'
          public 'model' => string 'some model'
  1 => 
    array 
      0 => 
        object(SimpleXMLElement)
          public 'name' => string 'some name'
          public 'model' => string 'some model'
      1 => 
        object(SimpleXMLElement)
          public 'name' => string 'some name'
          public 'model' => string 'some model'

and so on
我删除了中间数组以获得一个带有循环的数组(并将对象转换为数组):

结果是:

array 
  0 => 
    array
      'name' => string 'some name'
      'model' => string 'some model'
  1 => 
    array
      'name' => string 'some name'
      'model' => string 'some model'
  2 => ...
  3 => ...
  etc.
它完成了任务(使数组包含4个数组),但我想知道有什么更干净的方法来完成这个任务?是的,循环1000+个阵列肯定不是最好的主意。我不是在寻找确切的代码,只是一个想法

foreach ($items as $x) {
    foreach ($x as $y) {
        $item[] = (array) $y;
    }
}

您拥有的解决方案是最好的,因为如果您使用
array\u merge()
,那么您就不会有冲突的键,并且时间复杂度是
O(n)
,这非常好。

可能没有更好或更快(未测试),但可以选择:

$result = array_map('get_object_vars', call_user_func_array('array_merge', $items));
或:


如果您喜欢该语法,还可以使用
array\u walk\u recursive()
。不过,后端的算法是相同的。
$result = array_map('get_object_vars', call_user_func_array('array_merge', $items));
foreach(call_user_func_array('array_merge', $items) as $o) {
    $result[] = (array)$o;
}