Jump to content

PHP Array


meames

Recommended Posts

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

<?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

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.