Let's say I have an array of strings that I use to create variable variables:
$var_arr = ["item1", "item2", "item3"];
foreach ($var_arr as $item) {
$$item = array();
}
Then elsewhere in my code I have to recreate the variable variable based on a different data source:
$user_input = [ "prod1" => "widget", "qty1" => 3, "prod2" => "thingy", "qty2" => 1, "prod3" => "dingus", "qty3" => 7 ];
foreach ($user_input as $key => $value) {
$a = "item" . substr($key, -1);
array_push($$a, $value);
}
Are $$item and $$a the same variable, or do they reference different blocks of memory?