|
|
#1 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
|
Even Numbers
I'm back again, and this is for a modification I plan to make for my forumhome of my vBulletin software.
I've got it all mapped, except for one thing. Is there a way that I can have PHP check if, let's say, $var is a even number? (the variable value is a number). The variable will be using the forumid numbers, and thus I want it to find every even number forumid. I know the basic layout, but I need it to check is the id is an even number or not. I know how to do the layout of the coding, just need that php function. Thanks in advance!
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#2 (permalink) |
|
Race Surpass
Super #1
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,227 posts
Gave thanks: 18
Thanked 86 times
|
Use the "%" modulus operator.. (remainder of $a divided by 2)
PHP Code:
__________________
|
|
|
|
| This user thanks MarkRH for this great post! | GamingHybrid (August 16th, 2007) |
|
|
#3 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
|
so, I should replace $a with the variable I'm trying to check if its number is an even number, right?
Thank you MarkRH, you've been a great help like always ![]()
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#4 (permalink) |
|
Race Surpass
Super #1
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,227 posts
Gave thanks: 18
Thanked 86 times
|
Well, if you do an inline comparision, yes. Or you just call the function like:
if (is_even($myvariable)) then do whatever cause it's even. Otherwise.. do: if (($myvariable % 2) == 0) then do whatever cause it's even.
__________________
|
|
|
|
| This user thanks MarkRH for this great post! | GamingHybrid (August 16th, 2007) |
|
|
#5 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
|
PHP Code:
Parse error: syntax error, unexpected '[', expecting ')' in /home/gaminghy/public_html/forums/index.php(63) : eval()'d code on line 3
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#6 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
|
Is the above my variable causing the issue? If so, I know how to fix... actually, I'll try it now...
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#7 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
|
i found the issue, just trying to make it work with vBulletin now. thanks Mark!
![]()
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#8 (permalink) |
|
Race Surpass
Super #1
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,227 posts
Gave thanks: 18
Thanked 86 times
|
No.. don't change that is_even function at all. All it's meant to do is evaluate if a variable passed to it is even or not and return true or false.
In your main code: PHP Code:
PHP Code:
__________________
|
|
|
|
| This user thanks MarkRH for this great post! | GamingHybrid (August 16th, 2007) |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|