Jump to content

[SOLVED] PHP while, foreach loop HELP.


prkarpi

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/86252-solved-php-while-foreach-loop-help/
Share on other sites

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.

<?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.

 

 

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";
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.