Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How can I get value from variable which is string ?

$Member_Student        = 3600;
$selectedItem = "Member_Student";
$price = "$" . $selectedItem;
print_r($price); //prints $Member_Student instead of 3600

I cannot use eval function.

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Use curly braces to denote a variable:

$Member_Student        = 3600;
$selectedItem = "Member_Student";
$price = ${$selectedItem};
print_r($price); // prints 3600
share|improve this answer
add comment

use 2 $ signs:

var_dump($$selectedItem)
share|improve this answer
add comment

To get a variable from another variable containing its name use print_r($$selectedItem );

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.