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. Quote 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 . Quote 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?? Quote 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? Quote 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] ? Quote 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? Quote 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.. } Quote Link to comment https://forums.phpfreaks.com/topic/179575-array-help/#findComment-947721 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.