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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.