Skip to content

Instantly share code, notes, and snippets.

@forsvunnet
Created July 19, 2018 12:59
Show Gist options
  • Save forsvunnet/9a0d8d89ee6ec60700bd2fa31e61a330 to your computer and use it in GitHub Desktop.
Save forsvunnet/9a0d8d89ee6ec60700bd2fa31e61a330 to your computer and use it in GitHub Desktop.
Dot path resolver
<?php
function convert(&$arr, $path, $value) {
$keys = explode('.', $path);
foreach ($keys as $key) {
if ( ! isset( $arr[$key] ) ) {
$arr[$key] = [];
}
$arr = &$arr[$key];
}
$arr = $value;
}
$arr = [
'entry',
'somethother'=>'something',
];
convert( $arr, 'somethother.test.2', '11' );
var_dump( $arr );%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment