Jump to content

[SOLVED] Optimized if?!!!!


zignaltrack

Recommended Posts

i have a piece of code in front of me that i need to work with and it, to me, looks like a optimised if statement.. bt m new to php n it doesnt make sense to me.. was hopin if anyone could just tell me what does this line mean?

 

the define statements are

define('ROLE_ANONYMOUS', 1);

define('ROLE_REGISTERED', 2 | ROLE_ANONYMOUS);

define('ROLE_PUBLISHER', 2 | ROLE_REGISTERED);

define('ROLE_ADMIN', 4 | ROLE_PUBLISHER);

 

and the line i was hoping anyone could help me understand is..

 

$this->role = ($this->admin == 1)? ROLE_ADMIN : ROLE_REGISTERED;

 

 

anyone plz? :)

Link to comment
https://forums.phpfreaks.com/topic/108142-solved-optimized-if/
Share on other sites

:) yep very much.. thanks all..

 

i had to have that info cos there are places or functions that made me want to confirm this.. for e.g

 

    function setAdmin($isAdmin) {

        $this->admin = $isAdmin? 1 : 0;

        if ($this->admin == 1) {

            $this->role = ROLE_ADMIN;

        }

    }

 

this is to set the admin, cos admin is a field in the user table that can have a value of 0/1 stating notanadmin/isanadmin... what i dnt understand the need for the line $this->admin = $isAdmin? 1 : 0;?? what is this line trying to achive?!

Link to comment
https://forums.phpfreaks.com/topic/108142-solved-optimized-if/#findComment-554294
Share on other sites

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.