function - How to pass more arguments to a fuction from a foreach loop php

I have method that creates sms objects from user numbers in a foreach loop
$phones = "3444425,455667"; //get phone numbers from textarea
$phones = chop($phones,","); //remove last comma
$phones = multiexplode(array(","," ","\r\n",".","|",":"),$phones); //reformat and convert to array
$message = "foobar foo"; // get the message from form field
//**loop through phone numbers from form field and reformat */
foreach($phones as $phone){
//create multiple Sms Object(s)
$sms = new Sms($sender, $phone, $message, "18");
} //close loop
How can I pass the sms objects from the loop to my function like this
$response = $instance->sendBatchSMS($sms1,$sms2,$sms3,etc);
and not
$response = $instance->sendBatchSMS($sms1);
$response = $instance->sendBatchSMS($sms2);
$response = $instance->sendBatchSMS($sms3);
Answer
Solution:
try this:
$list = [];
foreach($phones as $phone){
$list[] = new Sms($sender, $phone, $message, "18");
}
call_user_func_array(array($instance, "sendBatchSMS"), $list);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: method illuminate\database\eloquent\collection::paginate does not exist.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.