How to use foreach function in the the case of arrays of arrays

<>

This question is an exact duplicate of:

Answers


Just one thing... In your echo statement you have $s wrapped in single quotes ('), the variable will not be read unless it's in double quotes ("). ie: ["$s"]. Or you can do [''.$s.''] or just remove the quotes all together [$s].

And now the fix...

foreach($array_data['AvailResponse']['OriginDestinationOptions']['OriginDestinationOption']['0']['onward']['FlightSegments']['FlightSegment'] as $array)
{
    echo $c=$array['FlightNumber'];
}

Not a very elegant solution, but it works.

A link to the code working: http://phpfiddle.org/main/code/k9s-3i1


Try like this

foreach($array_data as $array)
{
    if(is_array($array))
    {
        foreach($array as $arr)
        {
             //Do the stuff
        } 
    }  
     //Do the stuff
}

just check that whether it is an array or not each time.if it is then apply another foreach loop


You are trying to access the data in a known position. I don't see why you have to make a loop.

echo $array_data['AvailResponse']['OriginDestinationOptions']['OriginDestinationOption']['0']['onward']['FlightSegments']['FlightSegment']['$s']['FlightNumber'];


Need Your Help

Get UIPanGesture Distance Of A Swipe

objective-c uiswipegesturerecognizer

I am looking to get real time swipe data as a user swipes across the screen. Here is my code:

Automated user research, what are good strategies?

metrics user-testing

I am producing an online system to integrate a number of other systems using sharepoint as a portal. I would like good logging built in so I can actually see what my users are doing (without invading

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.