Jump to content
mosb3rgler

Help with a foreach loop issue from json source

Recommended Posts

Hey there folks,

Im trying to get a foreach loop working correctly from a json source epg heres my code:

https://pastebin.com/FjHj1EF6

Here is the current output, which.. while correct is only the first instance of these values i wanted using the foreach loop, i would love any tips on why my approach failed and to be pointed in the right direction.

While it has to be included:

$url = "https://mywebsite.fake/mlb.php?id={$arr['games'][0]["gamePk"]}";

this value isn't related to the assistance im asking for. that will work for my purposes later. but for now i just need to understand the issue with the foreach loop.

Thanks in advance for your thoughtful response.

mosb3rgler

Share this post


Link to post
Share on other sites

That Pastebin is private.

Share this post


Link to post
Share on other sites

ok, so i noticed i change the index after games to 1 or 2 etc, and then otherwise it shows everything i need it too.. is there an approach that can check each of the index and posting similar to if it was all with in the same array.

Share this post


Link to post
Share on other sites
1 minute ago, requinix said:

That Pastebin is private.

sorry about that i edited it to unlisted you can see it now.

Share this post


Link to post
Share on other sites

So you already have a foreach on the dates, suggesting you understand the foreach and the dates. Sounds like what you want is a secondary foreach on the $arr[games]...

Share this post


Link to post
Share on other sites
Posted (edited)

ahh i see what your saying now. but my question is how would it look when your factoring in multiple indexes with in games. because the way i have the foreach example setup im noting the initial index 0, so im not sure how to have it look to all indexes.

Edited by mosb3rgler

Share this post


Link to post
Share on other sites

actually, your explaination triggered the solution i nested 1 inside the other one, and used }} to close at the end, and got the results i was after very much thanks for the nudge bud. you guys are excellent teachers, you just know the right comments to make to make us take another look at it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.