You can use a loop containing the names and values โโof the properties you want to set.
For example, an object that has the properties "$ var1", "$ var2" and "$ var3", you can set them as follows:
$propertiesToSet = array("var1" => "test value 1", "var2" => "test value 2", "var3" => "test value 3"); $myObject = new MyClass(); foreach($propertiesToSet as $property => $value) {
source share