Jump to content

Accessing Values with in a Simple Multidimensional Array?


CoolHandLuke

Recommended Posts

I have the following code:

 

<?php
 
$m_array = array(
                                'species'  => "Northern",
                                'length'   => 3,
                                'color'    => array(
                                                            'firstColor'  => "brown",
                                                             'secondColor' => "copper"
                                                             ),
                               'bodyType' => "stocky"
);
 
        print_r($m_array);
 
?>
 

I can't seem to figure out how to print_r the value of 'firstColor'. How is this done?

 

Thank you!

Following up on Requinix's answer, print_r exists so you can just quick dump out an array or object. So you wouldn't print_r a single element.

 

His answer shows you how you can reference elements in multiple nested arrays.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.