Skip to content

Instantly share code, notes, and snippets.

@anver
Created July 28, 2018 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anver/5a919c8627bcdd2c22ac59950681e063 to your computer and use it in GitHub Desktop.
Save anver/5a919c8627bcdd2c22ac59950681e063 to your computer and use it in GitHub Desktop.
function test_set_elongated_keys() {
$data = [
'test' => 'value',
'level_one' => [
'level_two' => [
'level_three' => [
'replace_this_array' => [
'key_one' => 'testing',
'key_two' => 'value',
'special_key' => 'replacement_value',
'four' => 'another value'
]
],
'ordinary_key' => 'value'
]
]
];
$completeIterator = new RecursiveIteratorIterator( new RecursiveArrayIterator( $data ) );
$cfg = array();
foreach ( $completeIterator as $key => $value ) {
$current_depth = $completeIterator->getDepth();
for ( $i = $current_depth - 1; $i >= 0; $i-- ) {
$sub_iterator = $completeIterator->getSubIterator( $i );
$key = $sub_iterator->key() . '.' . $key;
}
$cfg[$key] = $value;
}
$copy = $completeIterator->getArrayCopy();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment