Jump to content

[SOLVED] Really quick question [not much sleep...]


lordphate

Recommended Posts

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

?

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];

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

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.