Search Results

Search found 1 results on 1 pages for 'user325282'.

Page 1/1 | 1 

  • Pass variable number of variables to a class in PHP

    - by user325282
    I need to pass a variable number of strings to instantiate different classes. I can always do a switch on the size of the array: switch(count($a)) { case 1: new Class(${$a[0]}); break; case 2: new Class(${$a[0]}, ${$a[1]}); break; etc... There has to be a better way to do this. If I have an array of strings ("variable1", "variable2", 'variable3", ...), how can I instantiate a Class without manually accounting for every possibility?

    Read the article

1