I'm wondering how I can create external variables (for lack of better terms) dynamically. What I mean by external variable is what holds the internal variable.
External variable
$external_variable
Internal variable
$external_variable = 'internal_variable';
Now let's say I want to create a different suffix for the external variable dynamically, is it possible?
Example using a forloop
for ($a=1; $a <= 3; $a++) {
$external_variable_$a
}
result
$external_variable_1
$external_variable_2
$external_variable_3
Does it make any sense to do this like this?
EDIT
I'm giving more details with real code. I'm actually trying to change $pw_monday so that every time the forloop iterates the $pw suffix becomes the next weekday in $_SESSION. Or maybe I'm too tired to figure out another way.
//get all the dates of previous week
$pw_monday = date("Y-n-j",strtotime($previousweek .' last Monday' ));
$pw_tuesday = date("Y-n-j",strtotime($pw_monday .' +1 day' ));
$pw_wednesday = date("Y-n-j",strtotime($pw_tuesday .' +1 day' ));
$pw_thursday = date("Y-n-j",strtotime($pw_wednesday .' +1 day' ));
$pw_friday = date("Y-n-j",strtotime($pw_thursday .' +1 day' ));
$pw_saturday = date("Y-n-j",strtotime($pw_friday .' +1 day' ));
$pw_sunday = date("Y-n-j",strtotime($pw_saturday .' +1 day' ));
//put all dates in session
for ($rn=1; $rn <= 7; $rn++) {
//request days
$requestNs ='request_'.$rn;
$_SESSION[$requestNs] = $pw_monday;
}
final result
$_SESSION[request_1] = $pw_monday;
$_SESSION[request_2] = $pw_tuesday;
//...get the drift
$myArr = ['var1' => 1, 'var2' => 2], and then doingextract($myArr). Should you ? - most likely no. As @Machavity has noted, what you really want to do is definitely achievable with a better solution.$_SESSION['request_1'] == $monday_date,$_SESSION['request_2'] == $tuesday_dateetc., where thedatevariables are like2014-3-10?