How to access and manipulate multi-dimensional array by key names / path?

前端 未结 10 2205
北恋
北恋 2020-11-21 07:35

I\'ve to implement a setter in PHP, that allows me to specify the key, or sub key, of an array (the target), passing the name as a dot-separated-keys value.

10条回答
  •  悲哀的现实
    2020-11-21 08:09

    Here a simple code to access and manipulate MD array. But there's no securities.

    setter :

    eval('$vars = &$array["' . implode('"]["', explode('.', strtolower($dot_seperator_path))) . '"];');
    $vars = $new_value;
    

    getter:

    eval('$vars = $array["' . implode('"]["', explode('.', strtolower($dot_seperator_path))) . '"];');
    return $vars;
    

提交回复
热议问题