Jump to content

Array's default value


Dat

Recommended Posts

How can I get $TEMPLATE's default value as true;

 

So that later when I create $TEMPLATE[uSER_CAN_EDIT] = false;

 

I can use that later with

if (TEMPLATE[uSER_CAN_EDIT] == true)
{
//Something
}
else if (TEMPLATE[uSER_CAN_EDIT] == false)
{
//Something else
}

 

I want all of the array's of $TEMPLATE's value to be true as default; so when if i were to change them later I can do what is above.

Link to comment
Share on other sites

You can't?  Well, you can like this:

 

$TEMPLATE['USER_CAN_EDIT'] = true;

 

But that's pointless...you should just use some database logic and find out whether or not they can use it.  Also, for the record, use ' ' around your array keys.  Please.

Link to comment
Share on other sites

In short, you can't do that. What you could do is check to see if a particular key has been set. Indeed, i'd reverse your logic. It would make more sense from a safety point of view to ensure that each option is false to start with. It should only be set to true if the required authorization is met. Doing it your way leaves you open to making a mistake allowing access to something you did not wish. So, i'd do this:

 

if(isset($TEMPLATE['USER_CAN_EDIT'])){
//allow editing
}else{
//don't allow
}

 

You would then allow editing just be adding the key to the array:

 

//conditions have been met to allow editing
$TEMPLATE['USER_CAN_EDIT'] = TRUE;//the actual value assigned would be irrelevant

 

Note that you would only add the key if you want to allow it. You wouldn't, for example, set $TEMPLATE['USER_CAN_EDIT'] to false to prevent editing, you would just not set it at all.

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.