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
https://forums.phpfreaks.com/topic/262403-really-simple-i-guess/
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.

 

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.

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.