The goal here is to loop through the multidimensional array below and find user's who live in a certain city. I only pasted a small part of the array so you could get a feel for the structure. It comes from the Facebook Graph API. This function below shoots back this error message: Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\pathweavr\friendtest.php on line 143
Line 143:
foreach ($location['city'] as $city) {
And here's the code:
$friends = $fqlResult;
$friends_BA = array();
foreach ($friends as $friend) {
$isBA = false;
if (is_array($friend['current_location'])) {
foreach ($friend['current_location'] as $location) {
if (isset($location)) {
foreach ($location['city'] as $city) {
$lowerName = strtolower($city);
if (strpos($lowerName, 'orlando') !== false || strpos($lowerName, 'gainesville') !== false) {
$friends_BA[] = $friend['name'];
continue 3; // skip to the next friend
}
}
}
}
}
}
d($friends_BA);
The array looks like this:
Array
(
[0] => Array
(
[name] => PERSONS NAME
[current_location] => Array
(
[city] => New York
[state] => New York
[country] => United States
[zip] =>
[id] => 108424279189115
[name] => New York, New York
)
)
[1] => Array
(
[name] => PERSONS NAME
[current_location] =>
)
[2] => Array
(
[name] => PERSONS NAME
[current_location] =>
)
[3] => Array
(
[name] => PERSONS NAME
[current_location] =>
)
[4] => Array
(
[name] => PERSONS NAME
[current_location] => Array
(
[city] => San Jose
[state] => California
[country] => United States
[zip] =>
[id] => 111948542155151
[name] => San Jose, California
)
)
[5] => Array
(
[name] => PERSONS NAME
[current_location] => Array
(
[city] => Boston
[state] => Massachusetts
[country] => United States
[zip] =>
[id] => 106003956105810
[name] => Boston, Massachusetts
)
)
Been playing around with it for an hour but can't seem to make it work. I'm getting invalid arguments on the second foreach statement.