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! Link to comment https://forums.phpfreaks.com/topic/296037-accessing-values-with-in-a-simple-multidimensional-array/ 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"] Link to comment https://forums.phpfreaks.com/topic/296037-accessing-values-with-in-a-simple-multidimensional-array/#findComment-1510611 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. Link to comment https://forums.phpfreaks.com/topic/296037-accessing-values-with-in-a-simple-multidimensional-array/#findComment-1510615 Share on other sites More sharing options...
CoolHandLuke Posted May 3, 2015 Author Share Posted May 3, 2015 Thank you both. Link to comment https://forums.phpfreaks.com/topic/296037-accessing-values-with-in-a-simple-multidimensional-array/#findComment-1510616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.