Dev0ps

Make a foreach with a JSON array

Posted 8 months ago by Dev0ps

code

array:51 [▼
  0 => {#925 ▼
    +"year": "404 BC"
    +"text": "Peloponnesian War: Lysander's Spartan armies defeated the Athenians and the war ends."
    +"html": "<a href="https://wikipedia.org/wiki/Peloponnesian_War" title="Peloponnesian War">Peloponnesian War</a>: <a href="https://wikipedia.org/wiki/Lysander" title="Lys ▶"
    +"links": array:4 [▶]
  }
  1 => {#930 ▼
    +"year": "775"
    +"text": "The Battle of Bagrevand puts an end to an Armenian rebellion against the Abbasid Caliphate. Muslim control over Transcaucasia is solidified and its Islamization ▶"
    +"html": "The <a href="https://wikipedia.org/wiki/Battle_of_Bagrevand" title="Battle of Bagrevand">Battle of Bagrevand</a> puts an end to an <a href="https://wikipedia.or ▶"
    +"links": array:6 [▶]
  }
  2 => {#937 ▶}
  3 => {#943 ▶}
  4 => {#945 ▶}
  5 => {#949 ▶}
  6 => {#953 ▶}
  7 => {#956 ▶}
  8 => {#960 ▶}
  9 => {#964 ▶}
  10 => {#968 ▶}
  11 => {#971 ▶}
  12 => {#975 ▶}
  13 => {#982 ▶}
  14 => {#984 ▶}
  15 => {#992 ▶}
  16 => {#994 ▶}
  17 => {#1001 ▶}
  18 => {#1003 ▶}
  19 => {#1005 ▶}
  20 => {#1009 ▶}
  21 => {#1011 ▶}
  22 => {#1016 ▶}
  23 => {#1019 ▶}
  24 => {#1023 ▶}
  25 => {#1025 ▶}
  26 => {#1033 ▶}
  27 => {#1040 ▶}
  28 => {#1042 ▶}
  29 => {#1045 ▶}
  30 => {#1051 ▶}
  31 => {#1054 ▶}
  32 => {#1057 ▶}
  33 => {#1060 ▶}
  34 => {#1064 ▶}
  35 => {#1070 ▶}
  36 => {#1074 ▶}
  37 => {#1078 ▶}
  38 => {#1081 ▶}
  39 => {#1085 ▶}
  40 => {#1090 ▶}
  41 => {#1093 ▶}
  42 => {#1097 ▶}
  43 => {#1101 ▶}
  44 => {#1104 ▶}
  45 => {#1108 ▶}
  46 => {#1112 ▶}
  47 => {#1116 ▶}
  48 => {#1120 ▶}
  49 => {#1124 ▶}
  50 => {#1126 ▶}
]

i tried

 foreach($TimeQuoute['year']['text'][0]['html'] as $group) {
        echo $group['year'][0]['text'];

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.