Php evaluate a string as variable and extract value of it -
<?php $i=2; $teststring='$_session["registered"]["firstname'.$i.'"]'; var_dump($teststring); die; if(isset(($teststring))){ //do } ?>
in above code want find value of $_session["registered"]["firstname2']
variable , need suggestion/trick
why not just
$foo = $_session['registered']["firstname$i"];
array keys strings, , can dynamically generated. there absolutely no difference in php between these two:
$foo = array('bar' => 'baz'); $x = 'bar'; echo $foo[$x]; echo $foo['bar'];
both output baz
.
Comments
Post a Comment