Today, We want to share with you multidimensional array to single array php.In this post we will show you array into single array, hear for convert multidimensional array into single we will give you demo and example for implement.In this post, i will learn about PHP Convert Multi-Dimentional Array Into Single Array with an example.
Convert multidimensional array into single array in php
While getting some mutiple row of data of array, the array will return in the form of multidimensionals array in php. At that case i need to convert single dimensional array in php.
Sample of multidimensional array
For example multidimensionals array
Array ( [0] => Array ( [0] => Array ( [websites] => pakainfo ) [1] => Array ( [websites] => 4cgandhi ) [2] => Array ( [websites] => infinityknow ) [3] => Array ( [websites] => rajkot ) [4] => Array ( [websites] => surat ) [5] => Array ( [websites] => dsp ) ) )
Above multi dimensional array need to converted into single dimensional array in php.
Use code to convert:
$singleArray = []; foreach ($parentArray as $childArray) { foreach ($childArray as $value) { $singleArray[] = $value; } }
After applying above code in php,the output will be
Results
Array ( [0] => pakainfo [1] => 4cgandhi [2] => infinityknow [3] => rajkot [4] => surat [5] => dsp )
I hope you get an idea about Convert multi dimensional array into single array in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.