多维数组转换成单数组



Array(
      [0] => Array(
        [0] => My Property
        [1] => Array(
            [0] => Tiles Market
            [1] => My Floor
            )
        )
)

array([0]=>My Property [1] => Tiles Market [2] => My Floor)
$arr = array(); // Your array content
$merged_array = array();
$ri = new RecursiveIteratorIterator(new RecursiveArrayIterator($arr));
foreach($ri as $r) {
   array_push($merged_array,$r);
}
echo "<pre>"; print_r($merged_array);

try this

$new_array = call_user_func_array('array_merge', $old_array);

Demo

你可以像下面这样使用RecursiveArrayIterator;

<?php
function MultiToOne($from, &$to) {
    $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($from));
    foreach($it as $k => $v) {
      $to[] = $v;
    }   
}

$arr = array(
      "0" => array(
        "0" => "My Property",
        "1" => array(
            "0" => "Tiles Market",
            "1" => "My Floor"
            )
        )
);
$myFinalArr = array();
MultiToOne($arr, $myFinalArr);
var_dump($myFinalArr);
?>

相关内容

  • 没有找到相关文章