note 116632 added to language.variables.variable
| From: | jefrey.sobreira | Date: | Sun, 01 Feb 2015 17:34:03 +0000 |
| Subject: | note 116632 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201573@lists.php.net to get a copy of this message | ||
If you want to use a variable value in part of the name of a variable variable (not the whole name
itself), you can do like the following:
<?php
$price_for_monday = 10;
$price_for_tuesday = 20;
$price_for_wednesday = 30;
$today = 'tuesday';
$price_for_today = ${ 'price_for_' . $today};
echo $price_for_today; // will return 20
?>
----
Server IP: 72.52.91.14
Probable Submitter: 179.178.249.90
----
Manual Page -- http://php.net/manual/en/language.variables.variable.php
Edit -- https://master.php.net/note/edit/116632
Del: integrated -- https://master.php.net/note/delete/116632/integrated
Del: useless -- https://master.php.net/note/delete/116632/useless
Del: bad code -- https://master.php.net/note/delete/116632/bad+code
Del: spam -- https://master.php.net/note/delete/116632/spam
Del: non-english -- https://master.php.net/note/delete/116632/non-english
Del: in docs -- https://master.php.net/note/delete/116632/in+docs
Del: other reasons-- https://master.php.net/note/delete/116632
Reject -- https://master.php.net/note/reject/116632
Search -- https://master.php.net/manage/user-notes.php