parse string of array in php -
how parse string of array can value of variable
sample string
$str = 'prices[holiday:waterpark][person:1_person]';
sample variable
$prices['holiday:waterpark']['person:1_person'] = 100;
i have tried using variables.variable way in php this
$prices['holiday:waterpark']['person:1_person'] = 100; $str = "prices\['holiday:waterpark'\]\['person:1_person'\]"; $str = str_replace('\\', '', $str); echo $$str;
but thats not working , error
"undefined variable: $prices['holiday:waterpark']['person:1_person']"
try this
<? $prices['holiday:waterpark']['person:1_person'] = 100; $str = "prices\['holiday:waterpark'\]\['person:1_person'\]"; $str = stripslashes($str); // careful passing $str untrusted source // make necessary variable filtering before! echo eval('return $' . $str . ';');
Comments
Post a Comment