How to display Multidimensional Associative Array in PHP

How to display an array like this?

Array ( 
    [0] => Array ( 
        [dogs] => Array ( 
            [Cordillera Autonomous Region (CAR)] => Array ( 
                [link] => /search/veterinarians/?vet&provid=1&animal=ZG9ncw==&keyword=Abra&keysearch=QWJyYQ==&c 
                [city] => Abra 
            ) 
        ) 
    )

1 answer

  • answered 2018-02-13 01:22 1000Nettles

    I believe you're most probably looking for an output similar to this:

    <?php
    
    foreach ($array as $subarray) {
        foreach ($subarray as $category) {
            foreach ($category as $key => $value) {
                echo $key . ' : <a href="' $value['link'] . '">' . $value['city'] '</a>';
            }
        }
    }
    
    ?>
    

    Completely up to you how you actually output the data, but the structure of it lends itself to an output similar to this. You can nest foreach loops very easily in PHP.