Drippingblood123 Posted October 30, 2009 Share Posted October 30, 2009 This is what I have to do. $teamname[1] = "Red Sox" $teamname[2] = "Giants" $teamname[3] = "White Sox" $teamname[4] = "Cubs" $teamname[5] = "Cubs" Interface: Number 1 to 5; Output: "The [name] won World Series number [#]. This is what I have so far. <? $array=array('Red Sox', 'Giants', 'White Sox','Cubs' ,'Cubs'); print_r($array ); echo "<br>"; foreach( $array as $key => $value){echo $value ." "; } ?> <form method = "post" action = ""> <input type = "Submit" value = "Who won the series?" /> </form> I'm not sure what to do next. Link to comment https://forums.phpfreaks.com/topic/179575-array-help/ Share on other sites More sharing options...
kaveman50 Posted October 30, 2009 Share Posted October 30, 2009 . Link to comment https://forums.phpfreaks.com/topic/179575-array-help/#findComment-947577 Share on other sites More sharing options...
Drippingblood123 Posted October 30, 2009 Author Share Posted October 30, 2009 Anyone know?? Link to comment https://forums.phpfreaks.com/topic/179575-array-help/#findComment-947581 Share on other sites More sharing options...
Drippingblood123 Posted October 30, 2009 Author Share Posted October 30, 2009 Does anyone know what to do? Link to comment https://forums.phpfreaks.com/topic/179575-array-help/#findComment-947592 Share on other sites More sharing options...
mikesta707 Posted October 30, 2009 Share Posted October 30, 2009 foreach($array as $key => $value){ echo "The " . $value . " won the World Series " . ($key + 1) . "<br />"; } [/code] ? Link to comment https://forums.phpfreaks.com/topic/179575-array-help/#findComment-947603 Share on other sites More sharing options...
Drippingblood123 Posted October 30, 2009 Author Share Posted October 30, 2009 That works but it displays everything before hand. How would I get it so that it only displays the results after I click the button? Link to comment https://forums.phpfreaks.com/topic/179575-array-help/#findComment-947698 Share on other sites More sharing options...
Alex Posted October 30, 2009 Share Posted October 30, 2009 Add a name the name 'submit' to your button. Then wrap the foreach statement inside of a isset() conditional, like.. if(isset($_POST['submit'])) { // Foreach here.. } Link to comment https://forums.phpfreaks.com/topic/179575-array-help/#findComment-947721 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.