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

  • Home
  • SEARCH
  • 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 6955817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:47:14+00:00 2026-05-27T14:47:14+00:00

I’m using the following code to loop through a multidimensional array and find users

  • 0

I’m using the following code to loop through a multidimensional array and find users that went to a certain university, in this case UCF.

$friends = $fqlResult;
$friends_BA = array();

foreach ($friends as $friend) {
$isBA = false;
if (is_array($friend['education'])) {
    foreach ($friend['education'] as $school) {
        if (isset($school)) {
            foreach ($school['school'] as $name) {
                if (strpos(strtolower($name['name']), 'University of Central Florida') !== false) {
                    $friends_BA[] = $friend['name'];
                    continue 3; // skip to the next friend
                }
            }
        }
    }
    }
}

d($friends_BA);

The multidimensional array looks like this. It’s a list of friends from the Facebook Graph API:

Array
(
[0] => Array
    (
        [name] => PERSON
        [education] => 
    )

[1] => Array
    (
        [name] => PERSON
        [education] => Array
            (
                [0] => Array
                    (
                        [school] => Array
                            (
                                [id] => 108087985890571
                                [name] => St. Andrew's School
                            )

                        [year] => Array
                            (
                                [id] => 138383069535219
                                [name] => 2005
                            )

                        [type] => High School
                    )

                [1] => Array
                    (
                        [school] => Array
                            (
                                [id] => 20697868961
                                [name] => Boston University
                            )

                        [concentration] => Array
                            (
                                [0] => Array
                                    (
                                        [id] => 108654845832522
                                        [name] => Business Administration
                                    )

                            )

                        [type] => College
                    )

                [2] => Array
                    (
                        [school] => Array
                            (
                                [id] => 108289315859633
                                [name] => University of Miami
                            )

                        [year] => Array
                            (
                                [id] => 138879996141011
                                [name] => 2013
                            )

                        [type] => Graduate School
                    )

            )

    )

[2] => Array
    (
        [name] => PERSON
        [education] => Array
            (
                [0] => Array
                    (
                        [school] => Array
                            (
                                [id] => 115444241803885
                                [name] => Saint Andrews High School
                            )

                        [year] => Array
                            (
                                [id] => 137616982934053
                                [name] => 2006
                            )

                        [type] => High School
                    )

                [1] => Array
                    (
                        [school] => Array
                            (
                                [id] => 112033702149888
                                [name] => Boca Raton High
                            )

                        [year] => Array
                            (
                                [id] => 137616982934053
                                [name] => 2006
                            )

                        [type] => High School
                    )

                [2] => Array
                    (
                        [school] => Array
                            (
                                [id] => 108087985890571
                                [name] => St. Andrew's School
                            )

                        [type] => High School
                    )

                [3] => Array
                    (
                        [school] => Array
                            (
                                [id] => 107573562605861
                                [name] => Duke University
                            )

                        [concentration] => Array
                            (
                                [0] => Array
                                    (
                                        [id] => 104045469631213
                                        [name] => Political science
                                    )

                            )

                        [type] => College
                    )

            )

    )

[3] => Array
    (
        [name] => PERSON
        [education] => 
    )

[4] => Array
    (
        [name] => PERSON
        [education] => Array
            (
                [0] => Array
                    (
                        [school] => Array
                            (
                                [id] => 106039752760627
                                [name] => Berwick Academy
                            )

                        [year] => Array
                            (
                                [id] => 137616982934053
                                [name] => 2006
                            )

                        [type] => High School
                    )

                [1] => Array
                    (
                        [school] => Array
                            (
                                [id] => 108087985890571
                                [name] => St. Andrew's School
                            )

                        [type] => High School
                    )

                [2] => Array
                    (
                        [school] => Array
                            (
                                [id] => 105690226130720
                                [name] => Northeastern University
                            )

                        [concentration] => Array
                            (
                                [0] => Array
                                    (
                                        [id] => 108654845832522
                                        [name] => Business Administration
                                    )

                            )

                        [type] => College
                        [classes] => Array
                            (
                                [0] => Array
                                    (
                                        [id] => 189873264368867
                                        [name] => 2011
                                    )

                            )

                    )

            )

    )

I’ve run a similar program to find user’s majoring in certain subjects that did work, but for some reason the code above doesn’t work. Here’s the one that is working:

$friends = $fqlResult;
$friends_BA = array();

foreach ($friends as $friend) {
$isBA = false;
if (is_array($friend['education'])) {
    foreach ($friend['education'] as $school) {
        if (isset($school['concentration'])) {
            foreach ($school['concentration'] as $concentration) {
                if (strpos(strtolower($concentration['name']), 'business') !== false) {
                    $friends_BA[] = $friend['name'];
                    continue 3; // skip to the next friend
                }
            }
        }
    }
    }
}

d($friends_BA);

As always, any help would be sincerely appreciated. Happy Holidays!

UPDATE

Anyone want to take a stab at this one?

 $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-27T14:47:15+00:00Added an answer on May 27, 2026 at 2:47 pm

    Your problem is case SensiTivity. You use strtolower on a string to check the university, however, the university string you posted has mixed case. Change it to this line and it should work:

    if (strpos(strtolower($name['name']), 'university of central florida') !== false) {
    

    If you want the cases to match, remove the strtolower, add the uppercase letters back in and it should match case as well.

    UPDATE

    The second part of the problem is $name['name'] should be just $name. Since you are accessing the school array directly, it is looping through that portion.

    if (strpos(strtolower($name), 'university of central florida') !== false) {
    

    That should do it. So basically the foreach was looping over the school array, so the name comes out as a string value instead of being apart of the array.

    UPDATE 2

    $lowerName = strtolower($name);
    if (strpos($lowerName, 'university of central florida') !== false
            || strpos($lowerName, 'ucf') !== false) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to loop through a bunch of documents I have to put
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.