Darkmatter5 Posted December 15, 2008 Share Posted December 15, 2008 Here's my code <?php $param=$HTTP_GET_VARS['param']; $options=array("values"=>array(0=>"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","num","all"), "text"=>array(0=>"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0-9","Show all")); foreach($options as $value) { echo "Values: $value[values], Text: $value[text]<br>"; } ?> My desired output is: Values: a, Text: A Values: b, Text: B etc... Values: num, Text: 0-9 Values: all, Text: Show all What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/137065-help-with-foreach-statement/ Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 For loop would be better for this situation. <?php $param=$_GET['param']; $options=array("values"=>array(0=>"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","num","all"), "text"=>array(0=>"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0-9","Show all")); $cnt = count($options["values"]); for ($i=0; $i<$cnt; $i++) { echo "Values: " . $options["values"][$i] . ", Text: " . $options["text"][$i] . "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/137065-help-with-foreach-statement/#findComment-715853 Share on other sites More sharing options...
JonnoTheDev Posted December 15, 2008 Share Posted December 15, 2008 for($x = 0; $x < count($options['values']); $x++) { echo "Values: ".$options['values'][$x].", Text: ".$options['text'][$x]."<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/137065-help-with-foreach-statement/#findComment-715856 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.