Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6962243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:38:03+00:00 2026-05-27T15:38:03+00:00

The goal here is to loop through the multidimensional array below and find user’s

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:38:04+00:00Added an answer on May 27, 2026 at 3:38 pm

    you don’t need 2 foreach’s

    $friends = $fqlResult;
    $friends_BA = array();
    foreach ($friends as $friend) {
      $isBA = false;
      if (is_array($friend['current_location'])) {
        $lowerName = strtolower($friend['current_location']['city']);
        if (strpos($lowerName, 'orlando') !== false || strpos($lowerName, 'gainesville') !== false) {
          $friends_BA[] = $friend['name'];
        }
      }
    }
    
    d($friends_BA);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looping through an array, and during each iteration of the loop, I'm calling
My goal here is to change the image in my gallery at certain times
My goal here is to create an array with the sum totals of every
My goal here is to create a very simple template language. At the moment,
My goal here is to make a button. I want the text to sit
My goal here is to open temp.php, explode by ### (line terminator), then by
So my goal here is to have a single search field in an application
I have a project here the goal is to merge multiple Access DB's into
Here's the goal: to replace all standalone ampersands with & but NOT replace those
Here is my ultimate goal... to take this xml file.. <?xml version=1.0?> <Songs> <Song>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.