PHP - Restructure multi-dimentional array into single dimention
2013-12-13 | Hits
Source
For example, we have array like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php array( 'test_1' => array( 'msg_1' => 'this is the first desc', 'msg_2' => 'this is the second desc', ), 'test_2' => 'this is the third desc', 'test_3' => array( 'msg_1' => array( 'foo_1' => 'this is the fourth desc', ), 'msg_2' => 'this is the fifth desc', ), 'this is the sixth desc', );
Desired result
What we want the output is
1 2 3 4 5 6 7 8 9
Array ( [0] => thisis the first desc [1] => thisis the second desc [2] => thisis the third desc [3] => thisis the fourth desc [4] => thisis the fifth desc [5] => thisis the sixth desc )
Source code
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php functionrestructure_array($obj) { if (!is_array($obj)) { returnarray($obj); }