php call array from string

后端 未结 4 402
面向向阳花
面向向阳花 2021-01-23 02:57

I have a string that contains elements from array.

$str = \'[some][string]\';
$array = array();

How can I get the value of $array[\'some\

4条回答
  •  故里飘歌
    2021-01-23 03:36

    // trim the start and end brackets    
    $str = trim($str, '[]');
    // explode the keys into an array
    $keys = explode('][', $str);
    // reference the array using the stored keys
    $value = $array[$keys[0][$keys[1]];
    

提交回复
热议问题