lordphate Posted March 25, 2009 Share Posted March 25, 2009 Okay so i'm doing an articles script and i want just categories, and i want it file based [the categories] so i figured i'd do something like $categories[0] = "Category 1"; $categories[1] = "Category 2"; now for my main script can i do include(DOC_ROOT."/themes/".$GLOBALS["THEME"]."/system/article_categories.inc.php"); foreach($categories as $cat) { $category["name"] = $cat; $category["id"] = current($categories); } I know this may be a really easy question, but i've had like 2 hours of sleep this week AND getting married tomorrow lol...thanks guys ? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 25, 2009 Share Posted March 25, 2009 I don't think so. When you use foreach() it copies the contents of an array in turn into the variable you supply "as". foreach ($array as $val) { Each element will, in turn, be copied into $val Normally you'd access an array with square brackets: $array[$index]; Quote Link to comment Share on other sites More sharing options...
lordphate Posted March 25, 2009 Author Share Posted March 25, 2009 Maybe i could use this instead: include(DOC_ROOT."/themes/".$GLOBALS["THEME"]."/system/article_categories.inc.php"); while(list($key,$val) = each($categories)) { $category["name"] = $val; $category["id"] = $key $categories[] = $category; }//while Quote Link to comment 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.