Jump to content

Really simple i guess...


eddioot

Recommended Posts

Hi all,

 

i think i am making a really stupid mistake but i have a problem with my php function that i do not get.

 

My function is:

function user_level($userlevel){

if($userlevel = 0){
	$level = test;
}
elseif($userlevel >= 1){
	$level = test1;
}


return $level;
}

 

In the cases i tried it on the userlevel is way higher than 1, but nothing returns when i echo the function.

Whenever i change the >=  to = and the exact number, it works fine. So the following does work:

 

elseif($userlevel = 767){
	$level = test1;
}

 

Am i doing something really stupid here? :P

Link to comment
Share on other sites

= is the assignment operator. You want the conditional of ==

 

function user_level($userlevel){
if($userlevel == 0){
	$level = "test";
}
elseif($userlevel >= 1){
	$level = "test1";
}


return $level;
}

Link to comment
Share on other sites

Hi premiso,

 

thanks for your repsonse.

 

My problem seems to be that the bigger than does not work. So >= is not resolving.

When i use = it does resolve..

 

I need to create the function so i can return levels when the value is between 1 - 10 and another level when it is between 11 - 20 and so on.

Link to comment
Share on other sites

 

My problem seems to be that the bigger than does not work. So >= is not resolving.

When i use = it does resolve..

 

 

Did you even try what I suggested? Your problem is that the first if statement, $userlevel = 0  will always be true because it is being assigned properly. If you set it to $userlevel == 0  it will resolve to false, as that is the CONDITIONAL operator and not the ASSIGNMENT operator and it will then go into the elseif.

 

If you want help I suggest trying what people suggest and reading into it, instead of assuming that they did not post anything helpful.

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.