Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Php nested array - How to get a value out

Posted on 2009-07-07
Medium Priority
Last Modified: 2012-05-07

I have a nested array in php:
[field_linkout] => Array
            [0] => Array
                    [nid] => 57
                    [view] => <a href="/content/about">About</a>

            [1] => Array
                    [nid] => 15
                    [view] => <a href="/content/learning" class="active">Learning</a>

            [2] => Array
                    [nid] => 55
                    [view] => <a href="/content/organising">Organising</a>



I need to display only the links in the [view] element.

This is how far I've got:

      foreach ($node->field_linkout as $linkoutarray ) {
            foreach ($linkoutarray as $linkdata => $link)
                print $link[view] . '<br/>';
    } //


But it is displaying the first value of both the [nid] and [view] elements. I just need the [view] value.

Any help would be really appriciated.
Thanks, Lk
Question by:leekey
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

Michal-Drozd earned 2000 total points
ID: 24793035
your code is wrong, try this:
      foreach ($node->field_linkout as $linkoutarray ) {
         print $linkoutarray[view] . '<br/>';

Open in new window


Expert Comment

ID: 24793055
little explanation:
This is array of array (2 levels). And your code was passing it like it was array of array of array (3 levels).

Author Comment

ID: 24793069
Thanks Michal - I can see what you mean with regards to 3 levels.
have now changed my code and its working correctly.
Thanks again, Lk

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question