Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old February 14th, 2003, 01:11 AM
tim tim is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 62 tim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 9 sec
Reputation Power: 7
Send a message via ICQ to tim
Dynamic IF statement

I have a very long line of code in the following example statement

if (archive == "Y")
condition ="blabalba";
else
condition ="qwerqwerqw";

if (condition) {
.
.
.CODE HERE
.
.
}

What i want to do here is, causing 'condition' to be evaluated to a different thing based on 'archive'. Is this possible in PHP?
__________________
Beginner

Reply With Quote
  #2  
Old February 14th, 2003, 07:40 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Re: Dynamic IF statement

Quote:
Originally posted by tim
I have a very long line of code in the following example statement

if (archive == "Y")
condition ="blabalba";
else
condition ="qwerqwerqw";

if (condition) {
.
.
.CODE HERE
.
.
}

What i want to do here is, causing 'condition' to be evaluated to a different thing based on 'archive'. Is this possible in PHP?


The statement evaluating $archive doesn't seem to be too long.
I see two branches, an if and an else. Am I missing something.

If you just want to shorten this if/else, then you can try this syntax:

$condition = $archive=="Y" ? "blabalba" : "qwerqwerqw";


Your if/else is now condensed to one line.


Hope this helps,

--
Wil Moore III
www.wilmoore.com

Reply With Quote
  #3  
Old February 16th, 2003, 06:51 PM
tim tim is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 62 tim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 9 sec
Reputation Power: 7
Send a message via ICQ to tim
Yeah, I know, ...thanks...but

What I really meant was $condition being of the following form

$condition = ($datenow < $enddate) && ($puboptions == "A" || $puboptions == "M")

..... not just plain 'qwerqewr'...etc

NOw replace the $condition in if with the above.

I thought i tried it but it doesn't work.

Reply With Quote
  #4  
Old February 17th, 2003, 03:25 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Your question really wasn't all that detailed in the first post...
Your second post was not much help either.

I'm not sure I'll be able to help you further until you can rethink your post and submit it in a form that is clear.

However, if I were to guess what you meant, I'd say that you may want to try replacing && with and.


Sorry 'bout that,
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Dynamic IF statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway