How to reffer dynamically to a php ARRAY variable(s)?

前端 未结 3 1714
执念已碎
执念已碎 2021-01-23 01:52

Everybody knows that you can access a variable in PHP using this: ${\'varName\'}. But when you need to get/set a variable witch is part of an array, why doesn\'t it work ? Suppo

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-23 02:55

    I recommend you not to use dynamic variables like ${$var}. What you want is modifying a multi-dimensional associative array according to a path of keys.

    This is a procedural example to keep it simple. You may want to put your hierarchical array and this functions inside a class.

提交回复
热议问题