0

I would like to know how to access all of the information contained in this array. Can you provide guidance on how to iterate through each element and retrieve the values for each field, so that I can use this data for further processing or display.

array:2 [▼
  "posts" => array:2 [▼
    "data" => array:4 [▼
      0 => array:4 [▼
        "full_picture" => "https://scontent.ftun16-1.fna.fbcdn.net/v/t15.5256-10/341249535_529506086050902_7427978687176293379_n.jpg?_nc_cat=103&ccb=1-7&_nc_sid=ad6a45&_nc_ohc=H0Oj3ltXQiE ▶"
        "message" => """
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam Excepteur si ▶
          #hashtag
          """
        "comments" => array:1 [▼
          "data" => array:10 [▼
            0 => array:2 [▼
              "message" => "up"
              "id" => "196295246492186_616295936666740"
            ]
            1 => array:2 [▼
              "message" => "up"
              "id" => "196295246492186_920142692563337"
            ]
            2 => array:2 [▶]
            3 => array:2 [▶]
            4 => array:2 [▶]
            5 => array:2 [▶]
            6 => array:2 [▶]
            7 => array:2 [▶]
            8 => array:3 [▶]
            9 => array:2 [▶]
          ]
        ]
        "id" => "107003655273452_196295246492186"
      ]
      1 => array:3 [▼
        "message" => """
          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostru ▶
          #hashtag
          """
        "comments" => array:1 [▼
          "data" => array:1 [▼
            0 => array:2 [▼
              "message" => "Lorem ipsum"
              "id" => "167296586058719_630099432294701"
            ]
          ]
        ]
        "id" => "107003655273452_167296586058719"
      ]
      2 => array:2 [▼
        "full_picture" => "https://scontent.ftun16-1.fna.fbcdn.net/v/t39.30808-6/277777079_120234453950372_5372326084507170677_n.jpg?stp=dst-jpg_p720x720&_nc_cat=105&ccb=1-7&_nc_sid=e3f86 ▶"
        "id" => "107003655273452_1100604277548667"
      ]
      3 => array:2 [▶]
    ]
    "paging" => array:1 [▼
      "cursors" => array:2 [▼
        "before" => "QVFIUlFORExqUzVKTTU3cHZAYOW05VVMyVmRxT2tRWTd1S19ia3UtM0owZAG1vcXJFdDdYTWtDTURfSDd3alNlcENQVEtOLVFHaVNMOEUyMS0zWXZAMMlRJcklHSjhDaVN4ZAlF2MU41NUppM3NQd0VyRk1tQ1ZA ▶"
        "after" => "QVFIUlRyWTI1cldDUDlKbWJBdGw5ZAmZAXWEZA2SzYtSXdobngwcHhCRWFqOGpFQUhhQkdkS0stTFBjcG1ZARUtNOG9peHpMRThIaURyQ01Ma1JvaGhYZAHpMcUlONDRyV2tJS296RFFxZADhkRk1wOGd4dVIxN1 ▶"
      ]
    ]
  ]
  "id" => "107003655273452"
]
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • 1
    A foreach is normally a beginners first port of call and then another one to process the data in an inner array ....... – RiggsFolly Apr 27 '23 at 15:56
  • 1
    https://stackoverflow.com/search?q=%5Bphp%5D+nested+array, the term you were missing for successful reseach was "nested", I guess. – Ulrich Eckhardt Apr 27 '23 at 16:15

1 Answers1

0

You can do it using recursive function like this:

function display($arr) {
    for ($i = 0; $i < count($arr); $i++) {
        if (is_array($arr[$i]) {
            display($arr[$i]);
        } else {
            echo $arr[$i];
        }
    }
}

then just use it

display($yourArray);
Grykarreos
  • 14
  • 3