How to flatten (compress) multi-dimensional array into one-dimensional array in PHP? -


i got array. want other 3 array come [0] => array. don't want unique value want merge array flat in [0] => array.

array  (   [0] => array     (         [0] => array             (                 [campaign] => xxx                 [phone] => 111                 [state] => cd             )           )   [1] => array     (         [0] => array             (                 [campaign] => zxxxzx                 [phone] => 111111                 [state] => zxxx             )           )    [2] => array     (         [0] => array             (                 [campaign] => aaaa                 [phone] => 111                 [state] => csd             )          )    [3] => array     (         [0] => array             (                 [campaign] => sasa                 [phone] => 111                 [state] => asas             )            ) ) 

this example of how important naming is. working basically:

$recordsgroups = array(     // first group:     array(         // record 1:         array(             'key1' => 'val1',             'key2' => 'val2',         ),         // record 2:         array(             'key1' => 'aaa',             'key2' => 'bbb',         ),     ),     // 2nd group:     array(         // record 3:         array(             'key1' => 'ccc',             'key2' => 'ddd',         ),     ), ); 

and trying is:

$records = array(); foreach ($recordsgroups $group)     foreach ($group $record)         $records[] = $record; 

which give you:

$records = array(     // record 1:     array(         'key1' => 'val1',         'key2' => 'val2',     ),     // record 2:     array(         'key1' => 'aaa',         'key2' => 'bbb',     ),     // record 3:     array(         'key1' => 'ccc',         'key2' => 'ddd',     ), ); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -