meames Posted April 5, 2008 Share Posted April 5, 2008 I am having trouble with arrays - I have been reading up on them all week and I really don't get it! I know how to create a basic array and push data to the end of it using array_push, but I need to store 2 sets of information for each part of the array and multidimensional array's seem to be the answer. However, I have created an array eg: $ThemeParks = array ( 'Alton Towers' =>array ( 'Nemesis', 'Air', 'Oblivion'), 'Thorpe Park' =>array( 'Inferno', 'Slammer') ) Now, I want to push a new set of data to the end of the array eg: Disneyland Big Thunder Mountain Space Mountain I just know I'm gonna kick myself for how easy this is, but I just can't seem to do it - any ideas? Thanks. Link to comment https://forums.phpfreaks.com/topic/99632-php-array/ Share on other sites More sharing options...
Barand Posted April 5, 2008 Share Posted April 5, 2008 <?php $ThemeParks = array ( 'Alton Towers' =>array ( 'Nemesis', 'Air', 'Oblivion'), 'Thorpe Park' =>array( 'Inferno', 'Slammer') ) ; $ThemeParks['Disneyland'] = array('Big Thunder Mountain', 'Space Mountain'); echo '<pre>', print_r($ThemeParks, true), '</pre>'; ?> Link to comment https://forums.phpfreaks.com/topic/99632-php-array/#findComment-509685 Share on other sites More sharing options...
quiettech Posted April 5, 2008 Share Posted April 5, 2008 Or, if you insist on array_push(), array_push($ThemeParks, array('Big Thunder Mountain', 'Space Mountain'), array(/*...*/), /*...*/); Link to comment https://forums.phpfreaks.com/topic/99632-php-array/#findComment-509691 Share on other sites More sharing options...
meames Posted April 5, 2008 Author Share Posted April 5, 2008 Thanks guys - I knew it would be simple, just couldn't get my head around it! Last question regarding this is how would I print just one item from the array, such as if I just wanted to output 'Nemesis' from 'Alton Towers' Link to comment https://forums.phpfreaks.com/topic/99632-php-array/#findComment-509829 Share on other sites More sharing options...
Barand Posted April 5, 2008 Share Posted April 5, 2008 echo $ThemeParks['Alton Towers'][0]; Link to comment https://forums.phpfreaks.com/topic/99632-php-array/#findComment-509830 Share on other sites More sharing options...
meames Posted April 5, 2008 Author Share Posted April 5, 2008 Thanks a lot - hopefully I can go away now and get this thing sorted! Link to comment https://forums.phpfreaks.com/topic/99632-php-array/#findComment-509853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.