According to @Faiz answer (which I accepted as the formal answer to my question) I created the following sample example.
If I had the class Customer:
class Customer
{
public $firstname;
public $lastname;
public $country;
public $gender;
...
}
and the web HTML form with INPUT/SELECT fields having names 'firstname','lastname','country', 'gender'...
<form action="..." method="post">
<input type="text" name="firstname" value="" />
<input type="text" name="lastname" value="" />
<select name="country">
<option value="AL">Albania</option>
<option value="BE">Belgium</option>
<option value="HR">Croatia</option>
...
</select>
<input type="radio" name="gender" value="M" />Man
<input type="radio" name="gender" value="F" />Woman
...
<input type="submit" value="Submit" />
</form>
usually in my action script I would map these form fields into class variables one by one as:
$Customer=new Customer();
$Customer->firstname=$_POST['firstname'];
$Customer->lastname=$_POST['lastname'];
$Customer->country=$_POST['country'];
$Customer->gender=$_POST['gender'];
...
$Customer->create();
But using variable variables I can easily map all associative array values (there could be a lot of them which is error prone) into class variables using the following one line foreach loop;
$Customer=new Customer();
foreach($_POST as $key=>$value) $Customer->$key=$value;
$Customer->create();
Note: For the sake of answer (logic) simplicity and clearness I omitted $_POST values sanitization.