I'm tryng without success to create a custom backend based on user ID, if user id is different the 1 or different then 2 show custom backend.
This is my code but it doesn't work, any help would be very appreciate it.
if ($current_user_id != 1 || $current_user_id != 2){ show custom backend
Thank you
I'm tryng without success to create a custom backend based on user ID, if user id is different the 1 or different then 2 show custom backend.
This is my code but it doesn't work, any help would be very appreciate it.
if ($current_user_id != 1 || $current_user_id != 2){ show custom backend
Thank you
Share Improve this question edited Jun 2, 2020 at 15:42 shanebp 5,0856 gold badges27 silver badges40 bronze badges asked Jun 2, 2020 at 15:38 user1818326user1818326 133 bronze badges 1- 3 if you're trying to show the custom backend if the user is not 1/2 then that logic will not work unless the user ID is both 1 and 2 at the same time, which is not possible. The logic you've written is not the logic you wanted. If the user is 2 then it resolves to true because the user is not 1. If the user is 1 then it resolves to 2 because the user is not 2. Remember, the computer takes things literally, and will do exactly what it says, not what it meant. – Tom J Nowell ♦ Commented Jun 2, 2020 at 16:07
2 Answers
Reset to default 2You do not want an OR, you want an AND.
Follow it through and substitute the values. If we are user 1, then it's true because we are not user 2, and true OR false resolves to true. Only one of them needs to be true for an OR to be true. If we are user 2, then it's true because we are not user 1, and false OR true also resolves to true.
Remember, a or b
is true if A, B, or both are true. I know what you meant, but the computer does not, and you have to be extremely exact.
When you say I do not want A or B, what you really meant was I do not want A and I do not want B.
so replace this:
if user is not 1 or user is not 2
with:
if user is not 1 and user is not 2
Or better yet:
if user is not in this array [ 1, 2]
Use: get_current_user_id()
$current_user_id = get_current_user_id();
if ($current_user_id != 1 && $current_user_id != 2){
//show custom backend
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742379812a4432902.html
评论列表(0条)