Jump to content

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

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.