[SOLVED] problem with if statement
04-17-08, 11:32 AM
Newbie Coder
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] problem with if statement
I'm having some issues with the following code. I have a habbit of using 'or' in my if statements & was told to use || but it still doesn't seem to be working. Any help would be great.
It's not spitting out any errors, its just not working properly.
04-17-08, 11:48 AM
Aspiring Coder
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
__________________
Can you think outside the box but remain inside the box?
04-17-08, 11:56 AM
Newbie Coder
Join Date: Apr 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Not sure what you're trying to do, but i did notice that at the end of the code, the final else value sets $plan to a string, rather than an integer. Now, I know php is much more forgiving about this than c++, which is my native language. Try setting the final else to set $plan to "0" rather than unknown. Or, provide a little more info about what you're trying to do.
04-17-08, 12:08 PM
Code Master
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Use either a switch statement or use arrays and search the arrays for the correct plan. This method is fairly ugly and impractical really
04-17-08, 12:14 PM
Aspiring Coder
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
Jay6390
Use either a switch statement or use arrays and search the arrays for the correct plan. This method is fairly ugly and impractical really
I second that.
__________________
Can you think outside the box but remain inside the box?
04-17-08, 12:20 PM
Code Master
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
And since I was bored, here's a working example of how it would be done with arrays
PHP Code:
$plan = '23' ; $foundplan = false ; $plans = array(); $plans [ 400 ] = array( 41 , 46 , 92 , 104 ); $plans [ 350 ] = array( 40 , 45 , 91 , 103 ); $plans [ 300 ] = array( 39 , 44 , 90 , 102 ); $plans [ 250 ] = array( 38 , 43 , 89 , 101 ); $plans [ 200 ] = array( 23 , 18 , 83 , 99 ); $plans [ 150 ] = array( 37 , 42 , 88 , 100 ); $plans [ 100 ] = array( 17 , 22 , 87 , 98 ); $plans [ 75 ] = array( 82 , 76 , 94 , 106 ); $plans [ 50 ] = array( 16 , 20 , 85 , 97 ); $plans [ 25 ] = array( 15 , 21 , 86 , 96 ); $plans [ 15 ] = array( 14 , 19 , 61 , 62 ); $plans [ 10 ] = array( 63 , 64 , 59 , 60 ); foreach( $plans as $k => $v ) { if( array_search ( strval ( $plan ), $v )!== false ) { $foundplan = $k ; break; } } $plan =( $foundplan )? $foundplan : 'Unknown' ; echo $plan ;
Jay
Last edited by Jay6390; 04-17-08 at 12:23 PM .
04-17-08, 12:23 PM
Aspiring Coder
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
__________________
Can you think outside the box but remain inside the box?
04-17-08, 12:24 PM
Aspiring Coder
Join Date: Aug 2007
Posts: 540
Thanks: 0
Thanked 0 Times in 0 Posts
HAHAHAHA you go the short way I'll got the long way.
__________________
Can you think outside the box but remain inside the box?
04-17-08, 12:24 PM
Code Master
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
I was going to do that one, but I realised it's just as long winded as the if statements really, just a bit more presentable
04-17-08, 12:31 PM
Newbie Coder
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off