prkarpi Posted January 16, 2008 Share Posted January 16, 2008 I have the following code: $SubGenreList = array("100"=>"2 Step, Acid, Big Beat, Electro, Funky Breaks, Hardcore Breaks, Nu Skool, Progressive", "116"=>"Acid, Epic, Hard, Progressive, Tech, Tribal"); echo $SubGenreList["$gID"]; It outputs $SubGenreList array with a given $gID number, so that if $gID = 100 it will print given array. My problem is that I can't get it to work like a loop with "while" or "foreach" statements so that I could add additional HTML with each output from array. I want it to work in similar ways like this: $arr=array("one", "two", "three"); foreach ($arr as $value) { echo "Value: " . $value . "<br />"; } Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/86252-solved-php-while-foreach-loop-help/ Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 Post your code that is not working. Quote Link to comment https://forums.phpfreaks.com/topic/86252-solved-php-while-foreach-loop-help/#findComment-440567 Share on other sites More sharing options...
prkarpi Posted January 16, 2008 Author Share Posted January 16, 2008 Post your code that is not working. $SubGenreList = array("100"=>"2 Step, Acid, Big Beat, Electro, Funky Breaks, Hardcore Breaks, Nu Skool, Progressive", "116"=>"Acid, Epic, Hard, Progressive, Tech, Tribal"); echo $SubGenreList["$gID"]; this code works fine, however, I want it to loop. -thank you. Quote Link to comment https://forums.phpfreaks.com/topic/86252-solved-php-while-foreach-loop-help/#findComment-440570 Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 <?php $SubGenreList = array("100"=>"2 Step, Acid, Big Beat, Electro, Funky Breaks, Hardcore Breaks, Nu Skool, Progressive", "116"=>"Acid, Epic, Hard, Progressive, Tech, Tribal"); foreach ($SubGenreList as $list) { echo $list . "\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86252-solved-php-while-foreach-loop-help/#findComment-440574 Share on other sites More sharing options...
prkarpi Posted January 16, 2008 Author Share Posted January 16, 2008 <?php $SubGenreList = array("100"=>"2 Step, Acid, Big Beat, Electro, Funky Breaks, Hardcore Breaks, Nu Skool, Progressive", "116"=>"Acid, Epic, Hard, Progressive, Tech, Tribal"); foreach ($SubGenreList as $list) { echo $list . "\n"; } ?> Thanks for the code. However I need the variable $gID to choose which array to display based on what costumer would choose on the web. So that this code would output a specifically chosen array. Please look at the variable $gID where the "echo" is located: $SubGenreList = array("100"=>"2 Step, Acid, Big Beat, Electro, Funky Breaks, Hardcore Breaks, Nu Skool, Progressive", "116"=>"Acid, Epic, Hard, Progressive, Tech, Tribal"); echo $SubGenreList["$gID"]; Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/86252-solved-php-while-foreach-loop-help/#findComment-440584 Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 That will output one array index's value, there is nothing to loop. Maybe this is what you meant but failed to ask? <?php <?php $SubGenreList = array("100"=>"2 Step, Acid, Big Beat, Electro, Funky Breaks, Hardcore Breaks, Nu Skool, Progressive", "116"=>"Acid, Epic, Hard, Progressive, Tech, Tribal"); $split = explode(', ',$SubGenreList[$gID]); foreach ($split as $list) { echo $list . "\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/86252-solved-php-while-foreach-loop-help/#findComment-440586 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.