eddioot Posted May 11, 2012 Share Posted May 11, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/262403-really-simple-i-guess/ Share on other sites More sharing options...
premiso Posted May 11, 2012 Share Posted May 11, 2012 = 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; } Quote Link to comment https://forums.phpfreaks.com/topic/262403-really-simple-i-guess/#findComment-1344771 Share on other sites More sharing options...
eddioot Posted May 11, 2012 Author Share Posted May 11, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262403-really-simple-i-guess/#findComment-1344774 Share on other sites More sharing options...
premiso Posted May 11, 2012 Share Posted May 11, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/262403-really-simple-i-guess/#findComment-1344776 Share on other sites More sharing options...
eddioot Posted May 11, 2012 Author Share Posted May 11, 2012 Ok, i misunderstood your suggestion and indeed it works. Sorry and thanks man, no need to get angry Quote Link to comment https://forums.phpfreaks.com/topic/262403-really-simple-i-guess/#findComment-1344796 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.