Pass variable number of variables to a class in PHP

前端 未结 7 1663
别跟我提以往
别跟我提以往 2021-02-14 14:12

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:
            


        
7条回答
  •  野性不改
    2021-02-14 14:34

    Look here. Does method 2 help ? Also, perhaps by moving the switch to the constructor (if that is practical) you would be able to hide this from the rest of the code.

提交回复
热议问题