SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Get Values from nested multidimensional Array

    Hi I am trying to get "fulltext" values from this json file on this Link

    I am getting only top of the array how can I get all values from all arrays even the nested ones

    Code:
            
    $json_output = json_decode($json, true);
    var_dump($json_output);
    foreach($json_output['results'] as $item) {
        echo '<br/>'. $item['fulltext'];

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    The linked item is not json, it's array notation.

    Personally, I'd use a preg_match_all, but as you want to loop:

    PHP Code:
    foreach($output['results'] AS $result) {
     foreach(
    $result['printouts']['Covers topic'] AS $topic) {
       echo 
    "<br />".$topic['fulltext'];
     }
     echo 
    "<br />".$result['fulltext'];

    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great Awesome

    thanks

    Quote Originally Posted by StarLion View Post
    The linked item is not json, it's array notation.

    Personally, I'd use a preg_match_all, but as you want to loop:

    PHP Code:
    foreach($output['results'] AS $result) {
     foreach(
    $result['printouts']['Covers topic'] AS $topic) {
       echo 
    "<br />".$topic['fulltext'];
     }
     echo 
    "<br />".$result['fulltext'];


  4. #4
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi StarLion

    I need to ask one more question for this:

    is it possible to make $result['fulltext'] as links that open a new window displaying the $topic['fulltext'] of its specific array?

    thanks
    Quote Originally Posted by StarLion View Post
    The linked item is not json, it's array notation.

    Personally, I'd use a preg_match_all, but as you want to loop:

    PHP Code:
    foreach($output['results'] AS $result) {
     foreach(
    $result['printouts']['Covers topic'] AS $topic) {
       echo 
    "<br />".$topic['fulltext'];
     }
     echo 
    "<br />".$result['fulltext'];


  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Theoretically, sure.
    Either have the new window call it's own fetch of the array and isolate the desired result, or pass the fulltext on to the page as a GET (not really recommended, but it'd work at least).
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  6. #6
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any example you can show me?

    Quote Originally Posted by StarLion View Post
    Theoretically, sure.
    Either have the new window call it's own fetch of the array and isolate the desired result, or pass the fulltext on to the page as a GET (not really recommended, but it'd work at least).

  7. #7
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Have the new window walk the array (foreach), looking for a result (or a covers-topic) that has the name you're looking for (which would be passed to it via a $_GET variable such as newwindow.php?name=SCI1021 ), and access that element's fulltext entry.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  8. #8
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks

    worked like a charm

    Quote Originally Posted by StarLion View Post
    Have the new window walk the array (foreach), looking for a result (or a covers-topic) that has the name you're looking for (which would be passed to it via a $_GET variable such as newwindow.php?name=SCI1021 ), and access that element's fulltext entry.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •