$success_flag = false;
$phone_number_array = "";
$phone_number_array = json_decode($_POST['phone_number_array'], true);
$phone_number_array=array_map('trim',$phone_number_array);
$forward_number_array = "";
$forward_number_array = json_decode($_POST['forward_number_array'], true);
$forward_number_array=array_map('trim',$forward_number_array);
$arrResponse = $forward_number_array;
try {
for ($counter=0; $counter < count($phone_number_array); $counter++) {
foreach ($client->account->incoming_phone_numbers->getIterator(0, 50, array(
"PhoneNumber" => $phone_number_array[$counter]
)) as $number
) {
$voice_url = "http://twimlets.com/forward?PhoneNumber=" . $forward_number_array[$counter];
$number->update(array(
"VoiceUrl" => $voice_url,
));
$success_flag = true;
}
}
} catch (Exception $e) {
$success_flag = false;
$error = "\n\nError in forward numbers : " . $e;
file_put_contents("debug_file.txt", print_r($error, true), FILE_APPEND);
}
if($success_flag==false){
$response = "no records found";
echo $response;
}else{
$response = "Changes saved successfully";
echo $response;
}