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 7829079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:36:34+00:00 2026-06-02T10:36:34+00:00

I have the following code $List2 = json_decode(file_get_contents(https://___URL____&format=json),true); the following works perfectly echo ‘<pre>’;print_r($List2);echo

  • 0

I have the following code

$List2 = json_decode(file_get_contents("https://___URL____&format=json"),true);

the following works perfectly

echo '<pre>';print_r($List2);echo '</pre>';

and produces e.g.

Array
(
[0] => Array
    (
        [uid] => 123456
        [name] => John Williams
        [pic_square] => http://nc4/565228_799523_q.jpg
        [birthday_date] => 07/31/1987
    )

[1] => Array
    (
        [uid] => 123789
        [name] => Jane Thompson
        [pic_square] => http://profile.ak.fbcdn.net/785505233_1702140670_q.jpg
        [birthday_date] => 07/31/1983
    )

[2] => Array
    (
        [uid] => 456789
        [name] => John Gaffney
        [pic_square] => http://profet/hprofile-ak-snc4/3717297628_q.jpg
        [birthday_date] => 07/31/1965
    )

[3] => Array
    (
        [uid] => 987654
        [name] => Johnny Illand
        [pic_square] => http://c4/41766_14329_q.jpg
        [birthday_date] => 07/31/1958
    )

I want to run a foreach to print the result somewhat neater obviously, so i’m trying the following:

$data = $List2['data'] ;

foreach ($data as $nr => $friends){

echo $friends[name].' - ';

}

But I get

Warning: Invalid argument supplied for foreach()

I’m stumped and it’s probably something easy!

  • 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-06-02T10:36:36+00:00Added an answer on June 2, 2026 at 10:36 am

    Try with:

    foreach ($List2 as $element)
        echo $element[name].' - ';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following Code package cyclist.project; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONException;
I have the following JQUERY code that I'm expecting to return 3 json results
I have the following controller code that returns a Json list object to my
UPDATED: I have the following code, where I am trying to use returned JSON
I have the following code to display JSON results from an AJAX request as
I have the following code, I want the end to be JSON that a
I have the following code: List<T> list = new List<T>(); IEnumerable<T> query1 = ...
I have the following code: List<HtmlMeta> metas = new List<HtmlMeta>(); foreach (Control c in
I have the following code: SPList list = web.Lists[this.ListName]; SPListItem item = list.Items.Add(); now
I have the following code: public List<IWFResourceInstance> FindStepsByType(IWFResource res) { List<IWFResourceInstance> retval = new

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.