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

?

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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.