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 ? Link to comment https://forums.phpfreaks.com/topic/151075-solved-really-quick-question-not-much-sleep/ 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]; Link to comment https://forums.phpfreaks.com/topic/151075-solved-really-quick-question-not-much-sleep/#findComment-793658 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 Link to comment https://forums.phpfreaks.com/topic/151075-solved-really-quick-question-not-much-sleep/#findComment-793666 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.