Friday, May 11, 2012

How to convert 2-demensional array in 1-demednsional array in php?

0
if you want to convet 2-dimensional array to 1-dimensional array following coding doing exactly without using foreach loop or while loop or for loop
<?php
$array = array(
0=> 'arfan',
1=> 'haider',

2=> array(
0=> 'azeem',
1=> 'jeme',
),
3=> array(
0=> 'haider',
1=> 'one'
)
);
echo "<pre>";
print_r($array); 
echo "</pre>";

 $arr = iterator_to_array(
new RecursiveIteratorIterator(new RecursiveArrayIterator($array)), 0);

echo "<pre>";
print_r($arr); 
echo "</pre>";
?>

No comments :

Post a Comment