Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php access multidimensional array by string

function get_multi($arr, $str) {
    foreach (explode('.', $str) as $key) {
        if (!array_key_exists($key, $arr)) {
            return NULL; 
        }
        $arr = $arr[$key];
    }

    return $arr;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #access #multidimensional #array #string
ADD COMMENT
Topic
Name
6+1 =