This question has been marked as duplicate, but I don't see any solution from the linked answer. Please re-open.
I have the following code in the script, where I am facing issues.
$phone = array();
$phone = safepost("phones"); //phones can be 123456789, 222331122, 5566445566
$phone = explode(',', $phone);
$sphone = array();
for($i=0; $i<count($phone);$i++){
$sphone[] = ['phone' => $phone[$i]];
}
//Loop through all from phone array
foreach ($sphone as $vv => $p) {
$sql = "INSERT INTO `sms` (`phone`, `message`, `sender`, `schedule`) VALUES
(".$conn->qstr($p['phone']).",".$conn->qstr($msg).", ".$conn->qstr($senderid).", ".$conn->qstr($sch).")";
$conn->Execute($sql);
}
I get parse error on line 9, when I try to encapsulate the $sphone[]
value then I get only [
as the value for $p['phone']
and if I dont then I get error as PHP Parse error: syntax error, unexpected '[' in
I tried with several possibilities, but am not able to achieve it.
The end result needs to be during the insert all comma separated phone numbers should get inserted to my database.
Any advice as where am going wrong?