Thomas Owens Thomas Owens - 1 year ago 69
PHP Question

Iterating over a complex Associative Array in PHP

Is there an easy way to iterate over an associative array of this structure in PHP:

The array

has a numbered index, with between 4 and 5 associative parts. So I not only need to iterate over
, but also
. The hard part is that different indexes have different numbers of parts (some might be missing one or two).

Thoughts on doing this in a way that's nice, neat, and understandable?

Answer Source

Nest two foreach loops:

foreach ($array as $i => $values) {
    print "$i {\n";
    foreach ($values as $key => $value) {
        print "    $key => $value\n";
    print "}\n";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download