PHP array and globals?

J'sylve

New member
For my php class hw I need to make my code do this:


displayProduct() function should:
1. Display a nice headline or heading (you might make the heading the first row of the table)
2. Start an HTML table before you output the data
3. Loop through the array (passed as a parameter), and output each item on one table row
4. End the HTML table after the loop

Here's my code:


# create arrays for Travel Agent

// global

$vacation_array = "vacation array name";

//end global





function create_array_vacations ( ) {
global $vacation_array;
$vacation_array = array();
$vacation_array[] = "ID: 54321, Vacation: Maui Magic in Hawaii, $1999.00, Best beaches, best snorkeling" ;
$vacation_array[] = "ID: 87654, Vacation: Cruise in Style, $4500.00, Luxury ship, ocean view with balcony" ;
$vacation_array[] = "ID: 09876, Vacation: London and Paris, $3999.00, I see London, I see France" ;
$vacation_array[] = "ID: 32198, Vacation: Ski Aspen, $1500.00, Swoosh, Swish, cut an edge in Aspen" ;
}

create_array_vacations();

function displayProduct($vacation_array){
print "Vacations Travel Site<br />";
print $vacation_array;
}


displayProduct($vacation_array);


foreach (displayProduct as $key=>$val){
print "$key = $val<br />";
}


What am I doing wrong?

Here the summery of what i needed to do :

1. Create a global variable $vacation_array at the top of your code.
2. Copy and paste the function above for your business type.
3. Write your own displayProduct($array) using a parameter, do not use 'global'
4. Call the create_array_vacation function above to initialize the global array variable
6. Call the displayProduct($vacation_array) function, pass the array as a parameter
 
Back
Top