Re: [PHP] true, false
At 23:37 09.03.2003, Liam Gibbs said: [snip] >Why is it the following code produces nothing? > >$responsesubmitted = FALSE; >print($responsesubmitted); > >I have an if statement that says if($responsesubmitted), but it doesn't work. [snip] because $responsesubmitted is false :) A "false" value is "empty", while true is "1" in PHP-speech (contrary to languages like C where false is defined either being "!true" or "0". In case the execution block after your if-statement doesn't get executed this construction works just as it should. -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] true, false
Why is it the following code produces nothing? $responsesubmitted = FALSE; print($responsesubmitted); I have an if statement that says if($responsesubmitted), but it doesn't work.
Re: [PHP] True || False ?
> "MM" == Maxim Maletsky <[EMAIL PROTECTED]> writes: > > Tim Ward writes: > > > > to take this a step further, PHP doesn't seem to have types at all > > try ... > > > > echo 1 + true; // gives 2 > > echo 1 . true; // gives 11 > > > > true is a constant that seems to equate to 1, false is 0. Or is > > this just my interpretation? > You are absolutely right. True = 1 False = 0 > make an if statement, or echo ... > Cheers, Maxim Maletsky Ummm... no, PHP does have types. You can see the difference between true and 1 if you use the === operator in your if statement rather than ==. In your examples you were implicitly converting from a boolean type to an integer or a string. Try this: print gettype(true) . "\n"; print gettype(0 + true) . "\n"; print gettype('' . true) . "\n"; -robin -- Robin Vickery. BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] True || False ?
You are absolutely right. True = 1 False = 0 make an if statement, or echo ... Cheers, Maxim Maletsky -Original Message- From: Tim Ward [mailto:[EMAIL PROTECTED]] Sent: Friday, February 16, 2001 6:41 PM To: 'Toby Butzon'; Jonathan Sharp Cc: [EMAIL PROTECTED] Subject: RE: [PHP] True || False ? to take this a step further, PHP doesn't seem to have types at all try ... echo 1 + true; // gives 2 echo 1 . true; // gives 11 true is a constant that seems to equate to 1, false is 0. Or is this just my interpretation? Tim Ward Senior Systems Engineer Please refer to the following disclaimer in respect of this message: http://www.stivesdirect.com/e-mail-disclaimer.html > -Original Message- > From: Toby Butzon [mailto:[EMAIL PROTECTED]] > Sent: 16 February 2001 04:49 > To: Jonathan Sharp > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP] True || False ? > > > Yes, you can return false. > > As for "true booleans", PHP doesn't really have a boolean > type - it does > have a sense of "true" and "not true" though. You can return false (a > case-insensitive constant with the value 0) or true (whose value is > probably 1 but could really be anything other than 0 or the empty > string). > > You can of course evaluate a true/false value as a regular > condition... > if (someFunc()) { > // do something if someFunc returns true > } else { > // do something if someFunc returns false > } > > ..You get the idea. > > --toby > > Jonathan Sharp wrote: > > > > How does php handle true and false? Do they act as true booleans? > > > > Can I do? > > > > function foo() > > { > > return false; > > } > > > > Thanks, > > -Jonathan > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] True || False ?
to take this a step further, PHP doesn't seem to have types at all try ... echo 1 + true; // gives 2 echo 1 . true; // gives 11 true is a constant that seems to equate to 1, false is 0. Or is this just my interpretation? Tim Ward Senior Systems Engineer Please refer to the following disclaimer in respect of this message: http://www.stivesdirect.com/e-mail-disclaimer.html > -Original Message- > From: Toby Butzon [mailto:[EMAIL PROTECTED]] > Sent: 16 February 2001 04:49 > To: Jonathan Sharp > Cc: [EMAIL PROTECTED] > Subject: Re: [PHP] True || False ? > > > Yes, you can return false. > > As for "true booleans", PHP doesn't really have a boolean > type - it does > have a sense of "true" and "not true" though. You can return false (a > case-insensitive constant with the value 0) or true (whose value is > probably 1 but could really be anything other than 0 or the empty > string). > > You can of course evaluate a true/false value as a regular > condition... > if (someFunc()) { > // do something if someFunc returns true > } else { > // do something if someFunc returns false > } > > ..You get the idea. > > --toby > > Jonathan Sharp wrote: > > > > How does php handle true and false? Do they act as true booleans? > > > > Can I do? > > > > function foo() > > { > > return false; > > } > > > > Thanks, > > -Jonathan > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] True || False ?
oops ... I think I got too far from your original question: yes, function returnMeFoo($foo=0) { if($foo) return true; return false; } if(returnMeFoo()) echo 'you will not see this echo'; elseif(returnMeFoo(1)) echo 'but if you see this means the function returned as true'; Cheers, Maxim Maletsky -Original Message- From: Maxim Maletsky Sent: Friday, February 16, 2001 2:40 PM To: 'Jonathan Sharp'; [EMAIL PROTECTED]; 'Jeff Oien' Subject: RE: [PHP] True || False ? Yeah, sure you can, if return is found in function it then exits it. for example avoiding 'else' statements: function returnMeFoo($foo=0) { if(!$foo) return "Hey, you forgot to type a number in"; if($foo>5) return "$foo is bigger then 5"; if($foo<5) return "$foo is less then 5"; return "Then, logically, $foo *IS* 5"; } // then call this function as echo ''.returnMeFoo(4); echo ''.returnMeFoo(5); echo ''.returnMeFoo(6); And see how fun it is! Cheers, Maxim Maletsky -Original Message----- From: Jonathan Sharp [mailto:[EMAIL PROTECTED]] Sent: Friday, February 16, 2001 1:26 PM To: [EMAIL PROTECTED] Subject: [PHP] True || False ? How does php handle true and false? Do they act as true booleans? Can I do? function foo() { return false; } Thanks, -Jonathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] True || False ?
Yeah, sure you can, if return is found in function it then exits it. for example avoiding 'else' statements: function returnMeFoo($foo=0) { if(!$foo) return "Hey, you forgot to type a number in"; if($foo>5) return "$foo is bigger then 5"; if($foo<5) return "$foo is less then 5"; return "Then, logically, $foo *IS* 5"; } // then call this function as echo ''.returnMeFoo(4); echo ''.returnMeFoo(5); echo ''.returnMeFoo(6); And see how fun it is! Cheers, Maxim Maletsky -Original Message- From: Jonathan Sharp [mailto:[EMAIL PROTECTED]] Sent: Friday, February 16, 2001 1:26 PM To: [EMAIL PROTECTED] Subject: [PHP] True || False ? How does php handle true and false? Do they act as true booleans? Can I do? function foo() { return false; } Thanks, -Jonathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] True || False ?
Yes, you can return false. As for "true booleans", PHP doesn't really have a boolean type - it does have a sense of "true" and "not true" though. You can return false (a case-insensitive constant with the value 0) or true (whose value is probably 1 but could really be anything other than 0 or the empty string). You can of course evaluate a true/false value as a regular condition... if (someFunc()) { // do something if someFunc returns true } else { // do something if someFunc returns false } ..You get the idea. --toby Jonathan Sharp wrote: > > How does php handle true and false? Do they act as true booleans? > > Can I do? > > function foo() > { > return false; > } > > Thanks, > -Jonathan > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] True || False ?
How does php handle true and false? Do they act as true booleans? Can I do? function foo() { return false; } Thanks, -Jonathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]