PHP Convert multi-dimentional array into single array

Today, We want to share with you PHP Convert multi-dimentional array into single array.In this post we will show you How to restructure multi-dimensional array with columns as rows?, hear for How to convert multi-dimensional array into single array using php? we will give you demo and example for implement.In this post, we will learn about Restructure multidimensional array of column data into multidimensional array of row data with an example.

PHP Convert multi-dimentional array into single array

There are the Following The simple About Convert multidimensional array into single array Full Information With Example and source code.

As I will cover this Post with live Working example to develop convert multidimensional array to single array laravel, so the convert associative array to single dimensional array in php is used for this example is following below.

Read Also:  advantages of mysql - Top 10 Major Advantages of Using MySQL

Restructure multi-dimentional array into single dimention

Simple PHP multi-dimentional array

Simple PHP – Restructure multi-dimentional array into single dimention

array(
‘argument_1’ => ‘Welcome To the Sachin Namste’,
‘argument_2’ => ‘Welcome To the Virat Namste’,
),
‘param_2’ => ‘Welcome To the Ravi Namste’,
‘param_3’ => array(
‘argument_1’ => array(
‘foo_1’ => ‘Welcome To the Mayur Namste’,
),
‘argument_2’ => ‘Welcome To the Trump Namste’,
),
‘Welcome To the Modi Namste’,
);

We want the Like this output is

Array
(
    [0] => Welcome To the Sachin Namste
    [1] => Welcome To the Virat Namste
    [2] => Welcome To the Ravi Namste
    [3] => Welcome To the Mayur Namste
    [4] => Welcome To the Trump Namste
    [5] => Welcome To the Modi Namste
)

PHP Source code

<?php
function restructure_array($obj) {
    if (!is_array($obj)) {
        return array($obj);
    }

    $gretting_message = array();
    foreach ($obj as $k => $sub_obj) {
        $tmp = restructure_array($sub_obj);
        $gretting_message = array_merge($gretting_message, $tmp);
    }
    return $gretting_message;
}

Web Programming Tutorials Example with Demo

Read :

Read Also:  Live chat code in php with demo and free download : Updated 2021

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about how to convert 2d array to 1d 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.