Hello,
How can I use the "value of an array element" as the "name of another variable"?
Here is my array:
$arr = array("zip_code","city","state","country","distance","population");
Now I need to access each value in the array, and use it as the name of a variable. This approach below did not work:
foreach($arr as $key=>$val){
if(!empty($GET[$val])){
${$val}=$GET[$val];
}
else {
${$val}=$_POST[$val];
}
If I were to do this manually, I would repeat the following 6 times, each time using a new name:
if(!empty($GET[zip_code])){$zip_code=$GET[zip_code];}else{$zip_code=$_POST[zip_code];}