Convert a String to Variable

后端 未结 9 2150
臣服心动
臣服心动 2020-12-01 05:43

I\'ve got a multidimensional associative array which includes an elements like

$data[\"status\"]
$data[\"response\"][\"url\"]
$data[\"entry\"][\"0\"][\"text\         


        
9条回答
  •  萌比男神i
    2020-12-01 06:26

    Found this on the Variable variables page:

    function VariableArray($data, $string) { 
        preg_match_all('/\[([^\]]*)\]/', $string, $arr_matches, PREG_PATTERN_ORDER); 
    
        $return = $arr; 
        foreach($arr_matches[1] as $dimension) { $return = $return[$dimension]; }
    
        return $return; 
    } 
    

提交回复
热议问题