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

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -