joecooper Posted May 4, 2008 Share Posted May 4, 2008 $location can be 1,2,3,4,5 or 6. how can i do an array so that $location will be changed as following 1=london, 2=paris etc... Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 4, 2008 Share Posted May 4, 2008 $places = array(' ','london','paris', ....); ... more code ... echo $places[$location]; // generates paris when $location =2 etc Quote Link to comment Share on other sites More sharing options...
tronicsmasta Posted May 4, 2008 Share Posted May 4, 2008 $location = array("location" => array(1 => "London", 2 => "Paris", 3 => "Bejing", 4 => "New York", 5 => "Los Angeles", 6 => "Kansas City")); echo $arr["location"][1]; // echos London echo $arr["location"][2]; // echos Paris echo $arr["location"][3]; // echos Bejing echo $arr["location"][4]; // echos New York echo $arr["location"][5]; // echos Los Angeles echo $arr["location"][6]; // echos Kansas City Quote Link to comment Share on other sites More sharing options...
tronicsmasta Posted May 4, 2008 Share Posted May 4, 2008 the one above my post is definatly easier... lol Quote Link to comment Share on other sites More sharing options...
Fadion Posted May 4, 2008 Share Posted May 4, 2008 AndyB has it, but anyway u can always decrement $location by 1, so: $places = array('london', 'paris'); $location = 1; //or 2, or 3 etc $location--; echo $places[$location]; Quote Link to comment Share on other sites More sharing options...
joecooper Posted May 4, 2008 Author Share Posted May 4, 2008 thanks to all! i will have a look at your methods. Quote Link to comment Share on other sites More sharing options...
Barand Posted May 5, 2008 Share Posted May 5, 2008 Just specify the first as 1 $places = array(1 => 'london', 'paris', 'bejing', 'new york', ...); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.