CoolHandLuke Posted May 3, 2015 Share Posted May 3, 2015 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! Quote Link to comment Share on other sites More sharing options...
requinix Posted May 3, 2015 Share Posted May 3, 2015 The firstColor is inside the color array which is inside the $m_array array. $m_array["color"]["firstColor"] Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 3, 2015 Share Posted May 3, 2015 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. Quote Link to comment Share on other sites More sharing options...
CoolHandLuke Posted May 3, 2015 Author Share Posted May 3, 2015 Thank you both. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.