0

I'm having

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

and i want out as

array([0]=>My Property [1] => Tiles Market [2] => My Floor)
Eddie
  • 26,593
  • 6
  • 36
  • 58
  • 2
    possible duplicate of [How to Flatten a Multidimensional Array?](http://stackoverflow.com/questions/1319903/how-to-flatten-a-multidimensional-array) – Nils Jun 11 '14 at 07:31
  • You can use [RecursiveArrayIterator](http://www.php.net//manual/en/class.recursivearrayiterator.php). See my answer and demo [here](http://stackoverflow.com/questions/24156933/mutidimentional-array-into-single-array-in-php/24161016#24161016) – Hüseyin BABAL Jun 11 '14 at 10:49

3 Answers3

0
$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);
M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76
0

try this

$new_array = call_user_func_array('array_merge', $old_array);
KAsh
  • 304
  • 5
  • 23
  • FYI: this appeared in the low quality posts queue because someone flagged it. Your answer appears plausible, so I presume it is because it is a code-only answer. – Oliver Matthews Jun 11 '14 at 08:55
0

Demo

You can do that with RecursiveArrayIterator like below;

<?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);

?>
Hüseyin BABAL
  • 15,400
  • 4
  • 51
  • 73