Jump to content

[SOLVED] is big ARRAY a good idea?


prkarpi

Recommended Posts

I have the following code:

 

$GLOBAL_ARRAY_LINK = "<a href=\"" . $GLOBAL_LINK . "Artists$SID&action=sf";

 

$SubGenreList = array("100"=>"$GLOBAL_ARRAY_LINK&gID=11\">2 Step</a>, $GLOBAL_ARRAY_LINK&gID=12\">Acid</a>, $GLOBAL_ARRAY_LINK&gID=12\">Big Beat</a>, $GLOBAL_ARRAY_LINK&gID=13\">Electro</a>, $GLOBAL_ARRAY_LINK&gID=14\">Funky Breaks</a>, $GLOBAL_ARRAY_LINK&gID=15\">Hardcore Breaks</a>, $GLOBAL_ARRAY_LINK&gID=16\">Nu Skool</a>, $GLOBAL_ARRAY_LINK&gID=17\">Progressive</a>", "116"=>"Acid, Epic, Hard, Progressive, Tech, Tribal");

 

$split = explode(', ',$SubGenreList[$gID]);

 

foreach ($split as $list) {

  echo $list . "<br>";

}

 

Moreover, this array will get much bigger with about $gID=50 or so. In other words I will have about 50 items in array. Is there a better solution? Perhaps XML, since I don't want to use DB for it.

Link to comment
https://forums.phpfreaks.com/topic/86319-solved-is-big-array-a-good-idea/
Share on other sites

I have the following code:

 

$GLOBAL_ARRAY_LINK = "<a href=\"" . $GLOBAL_LINK . "Artists$SID&action=sf";
$SubGenreList = array("100"=>"$GLOBAL_ARRAY_LINK&gID=11\">2 Step</a>, $GLOBAL_ARRAY_LINK&gID=12\">Acid</a>, $GLOBAL_ARRAY_LINK&gID=12\">Big Beat</a>, $GLOBAL_ARRAY_LINK&gID=13\">Electro</a>, $GLOBAL_ARRAY_LINK&gID=14\">Funky Breaks</a>, $GLOBAL_ARRAY_LINK&gID=15\">Hardcore Breaks</a>, $GLOBAL_ARRAY_LINK&gID=16\">Nu Skool</a>, $GLOBAL_ARRAY_LINK&gID=17\">Progressive</a>", "116"=>"Acid, Epic, Hard, Progressive, Tech, Tribal");

$split = explode(', ',$SubGenreList[$gID]); 

foreach ($split as $list) {
  echo $list . "<br>";
}

 

Moreover, this array will get much bigger with about $gID=50 or so. In other words I will have about 50 items in array. Is there a better solution? Perhaps XML, since I don't want to use DB for it.

You could neaten the code up quite a bit, and using caps for variable names is poor style IMO. Constants (and globals) are normally defined using caps.

 

But yeah, this code could be much simpler and your site more dynamic in nature if you used a database instead of hard coding this into your app.

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.