I'm trying to grab all the keys of a multidimensional array and format them a certain way. Here's a partial array:
$ini_config['aaa']['email']['main'] = 'me@name.com';
$ini_config['bbb']['email']['ccc'] = 'you@name.com';
$ini_config['bbb']['phone']['local'] = '800-555-1212';
$ini_config['bbb']['phone']['skype'] = '744-222-1234';
$ini_config['ccc']['phone']['main'] = 'domain.com';
$ini_config['ccc']['domain']['https'] = 'https://www. domain.com';
$ini_config['ccc']['fax'] = '744-222-1237';
and here's the format I need them in:
aaa_email_main
bbb_email_ccc
bbb_phone_local
bbb_phone_skype
ccc_phone_main
ccc_domain_https
ccc_fax
This script is the closest I've been able to come to what I need:
<?php
rloop($ini_config);
function rloop($array) {
global $full_key;
foreach($array as $key => $value) {
if(is_array($value) ) {
$full_key .= $key .'_';
$array[$key] = rloop($array[$key]);
}
else {
$array[$key] = (string) $value;
$filename = $full_key . $key;
echo 'filename: '. $filename . PHP_EOL;
$full_key = '';
}
}
}
N.B. The number of levels can be from 1 to 4, and all keys are strings.
Thanks