Perad Posted December 29, 2006 Share Posted December 29, 2006 I have an array which contains the names on an input form and image names.[code]$maps["Beltot"] = "beltot.jpg";$maps["Brecourt"] = "brecourt.jpg";$maps["Burgundy"] = "burgundy.jpg";$maps["Caen"] = "caen.jpg";$maps["Carentan"] = "carentan.jpg";$maps["El Alamein"] = "elala.jpg";$maps["Leningrad"] = "leningrad.jpg";$maps["Matmata"] = "matmata.jpg";$maps["Moscow"] = "moscow.jpg";$maps["Rostov"] = "rostov.jpg";$maps["St.Mere Eglise"] = "stmere.jpg";$maps["Stalingrad"] = "stalingrad.jpg";$maps["Toujane"] = "toujane.jpg";$maps["Villers-Bocage"] = "villers.jpg";$maps["Wallendar"] = "wallendar.jpg";[/code]I have called the values from the database.[code]$map1 = $row['map1'];$map2 = $row['map2'];[/code]How do i compare $map1 with the $maps array to find the right image? Link to comment https://forums.phpfreaks.com/topic/32168-how-do-i-loop-through-this-array/ Share on other sites More sharing options...
glenelkins Posted December 29, 2006 Share Posted December 29, 2006 Lets assume the chosen map in $map1 is "Caen"[code]$chosen_map_image = $maps[$map1];[/code] Link to comment https://forums.phpfreaks.com/topic/32168-how-do-i-loop-through-this-array/#findComment-149309 Share on other sites More sharing options...
ted_chou12 Posted December 29, 2006 Share Posted December 29, 2006 try ucword() so you get all the letters in the word lower case, then add ".jpg" to the end of each word, however, I do find some exceptions such as $maps["El Alamein"] = "elala.jpg";$maps["Villers-Bocage"] = "villers.jpg";may be you should change these to fit the rest. Link to comment https://forums.phpfreaks.com/topic/32168-how-do-i-loop-through-this-array/#findComment-149310 Share on other sites More sharing options...
craygo Posted December 29, 2006 Share Posted December 29, 2006 [code]<?phpforeach($maps as $map => $pic){ if($map1 == "$map"){ echo "<img src=\"$pic\">"; }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32168-how-do-i-loop-through-this-array/#findComment-149320 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.