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... Link to comment https://forums.phpfreaks.com/topic/104126-solved-array/ 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 Link to comment https://forums.phpfreaks.com/topic/104126-solved-array/#findComment-533105 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 Link to comment https://forums.phpfreaks.com/topic/104126-solved-array/#findComment-533106 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 Link to comment https://forums.phpfreaks.com/topic/104126-solved-array/#findComment-533108 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]; Link to comment https://forums.phpfreaks.com/topic/104126-solved-array/#findComment-533109 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. Link to comment https://forums.phpfreaks.com/topic/104126-solved-array/#findComment-533112 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', ...); Link to comment https://forums.phpfreaks.com/topic/104126-solved-array/#findComment-533113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.