0
<?php        
     $i=2;
     $teststring='$_SESSION["REGISTERED"]["FirstName'.$i.'"]';      
     var_dump($teststring); 
     die; 
     if(isset(($teststring))){
         //do something 
     }
?>

In above code I want find the value of $_SESSION["REGISTERED"]["FirstName2'] variable , I need suggestion/trick

2 Answers 2

2

Why not just

$foo = $_SESSION['REGISTERED']["FirstName$i"];

Array keys are just strings, and they CAN be dynamically generated. There is absolutely no difference in PHP between these two:

$foo = array('bar' => 'baz');
$x = 'bar';

echo $foo[$x];
echo $foo['bar'];

both will output baz.

Sign up to request clarification or add additional context in comments.

1 Comment

bro , I already spend a day on this but you saved my other day now , thank you very much, this is working as u said
0

you don't need extra quote for FirstName:

$teststring=$_SESSION["REGISTERED"]["FirstName".$i]; 

will simply work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.