Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-23-2007, 01:48 PM if(){} problem
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
I was wondering if
PHP Code:
if 
can involve non numerical stuff like is this possible? I've been trying to get it to work but had no luck so maybe there is another way of doing it that I don't know of...

PHP Code:
$a x;
$b y;
if (
$a $b){
$c 0;
} else {
$c 1;

thanks
MoForce is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-23-2007, 02:03 PM Re: if(){} problem
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Of course it's possible.
Your problem is surely that you don't do a test in your if, but an assignation.

Remember:
1 = means an assigantion
PHP Code:
$x=4;
$y=true
2 = means a comparison, with casting between different types
PHP Code:
1==3  //return false
1=='1'  //return true
'a'=='A'  /return false
4
!=true //return true 
3 = mean a comparison, but without type casting
PHP Code:
1==='1'  //false
'a'==='a' //true
1!=='1'  //true 
So, in your test, try to put 2 = in your if statements
PHP Code:
if ($a == $b){
  
$c 0;
} else {
  
$c 1;

</span></span>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 12-23-2007, 02:06 PM Re: if(){} problem
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
Quote:
Originally Posted by tripy View Post
Of course it's possible...
Thanks! It worked like a charm!
MoForce is offline
Reply With Quote
View Public Profile
 
Old 12-23-2007, 06:51 PM Re: if(){} problem
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
An if statement simply checks weather a condition is true, as in
PHP Code:
if(condition) {...} 
What ever 'condition' might be (given there are no errors) - a comparison, an assignment, a function call etc. - if simply checks weather it returns true, and if so executes the code within brackets.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to if(){} problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19647 seconds with 12 queries