PHP – Accessing Multidimensional Array Values

The thing that is probably tripping you up is that suitability is an array of arrays not just an array so in an example where you want to get the species_name property of the first second top level element you would use something like

$array[1]["suitability"][0]["species_name"];

It’s worth noting that your first array does not contain a “suitability” value so that would not be able to be accessed. In a foreach loop you could use a construct similar to this:

foreach($array as $value){
    if (isset($value["suitability"])){
        echo $value["suitability"][0]["species_name"];
    }
}

Leave a Comment