PHP Array comparison and filtering
I'm newer to PHP and sorting out some code. This is taking two phone
number lists… then pulling the numbers in the 2nd list OUT of the first
list, making a new filtered list. The full code worked fine when just
pulling in one list. Now that I've modified it to filter the list based a
2nd list, the code now fails and I'm getting this warning:
Warning: Illegal string offset 'phone_number' in /var/www/html/send.php on
line 7
// Get all of the phone numbers from the List
$sql = "SELECT phone_number FROM dial_list WHERE list_id='$list'";
$result = mysqli_query($link, $sql);
echo mysqli_error($link);
foreach ($result as $row) {
$all_people[] = $row['phone_number'];
}
// Get phone numbers from our DNC list
$sql = "SELECT phone_number FROM dial_dnc";
$result = mysqli_query($link, $sql);
echo mysqli_error($link);
foreach ($result as $row) {
$dnc_people[] = $row['phone_number'];
}
// Remove DNC numbers from list
$filtered_people = array_diff($all_people, $dnc_people);
foreach ($filtered_people as $row) {
$people[] = $row['phone_number'];
}
Line 79 (where the warning comes from) is: $people[] = $row['phone_number'];
Any help to pinpoint the error or an improvement on how to accomplish this
filtering would be greatly appreciated!
No comments:
Post a Comment