Jump to content

Array question


Recommended Posts

I want to teach myself to write a page at load from an array. That way all the would need to be changed would be the array entries. This would probably be better using an SQL database, but I want to learn this way first. I thought it would be a good excercise.What I want to write is a menu with the item, description, and price. I'm trying to figure out the best way to set up an array with this information. The best way I seem to be able to figure this out right now would be this:

		   <?php			$menu = array			(			 "first_item"=>array			   "first_item",			   "first_item_description",			   "first_item_price"			   ),			  "second_item"=>array			   (			   "second_item",			   "second_item_description",			   "second_item_price"			   ),			);			?>

...and so on.Is this the best way to write a multi-dimensional array, or is there a better way? If my thinking is right, and that's always subject to interpretation :) , I would use a loop to go through each array using "echo" statements to write the code for each menu item. I know there's probably a better way to do this, but right now I want to learn how to do this using the data from an array. This is just an excercise, hopefully not in futility :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...