Posted inphp

how to convert multidimensional array to single array in php?

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype