Monday, November 5, 2012

php multidimensional array to single dimension array

<?php 

php convert multidimensional array to single dimension array

convert multidimensional array to single array php



function multidimensional_array_to_single_dimension_array($array) { 
   if (!
$array) return false;
   
$flat = array();
   
$iterator  = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
  
   foreach (
$iterator as $value$singhal[] = $value;
   return 
$singhal;
}
$arr=array(1,2,array(4,5),6,array(7,8,array(9,10,11,array(12,13,14))));

 
 
print_r(multidimensional_array_to_single_dimension_array($arr)); ?>



OUTPUT:

Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 [4] => 6 [5] => 7 [6] => 8 [7] => 9 [8] => 10 [9] => 11 [10] => 12 [11] => 13 [12] => 14 )


5 comments:

  1. Try this :

    http://stackoverflow.com/questions/526556/how-to-flatten-a-multi-dimensional-array-to-simple-one-in-php/14972714#14972714

    http://stackoverflow.com/questions/1319903/how-to-flatten-a-multidimensional-array/14972389#14972389

    ReplyDelete
  2. Touche. Solid arguments. Keep up the amazing spirit.

    ReplyDelete
  3. I have read so many articles or reviews on the topic
    of the blogger lovers but this article is actually a good piece of writing, keep it up.

    ReplyDelete
  4. Expert plastic extrusion companies serve the vital function of creating specific shapes out of hard plastic that are used to make various other products like
    tubing, casing, and more. The twist should also be
    built to meet a given style of die. Extruders may be divided into three general types :.

    ReplyDelete

If you Satisfied , Please Leave a comment