Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

PHP - Convert multidimensional array to 2D array with dot notation keys

$
0
0

There are plenty of tips and code examples out there of accessing PHP arrays with dot notation, but I would like to do somewhat the opposite. I would like to take a multidimensional array like this:

$myArray = array('key1' => 'value1','key2' => array('subkey' => 'subkeyval'    ),'key3' => 'value3','key4' => array('subkey4' => array('subsubkey4' => 'subsubkeyval4','subsubkey5' => 'subsubkeyval5',        ),'subkey5' => 'subkeyval5'    ));

And turn it into this (likely through some recursive function):

$newArray = array('key1'                    => 'value1','key2.subkey'             => 'subkeyval','key3'                    => 'value3','key4.subkey4.subsubkey4' => 'subsubkeyval4','key4.subkey5.subsubkey5' => 'subsubkeyval5','key4.subkey5'            => 'subkeyval5');

Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>