Tudo sobre programação, banco de dados, internet, tecnologias, engenharia de software, dicas, tutoriais, dúvidas, apostilas e muito mais...
terça-feira, 25 de novembro de 2008
Booleans Values in PHP
hi, today I was searching about data types in PHP and I found this excellent material. You will never have doubts in Booleans data types in PHP.
A Boolean value is one that is in either of two states. They are known as True or False values, in programming. True is usually given a value of 1, and False is given a value of zero. You set them up just like other variables:
$true_value = 1;
$false_value = 0;
You can replace the 1 and 0 with the words "true" and "false" (without the quotes). But a note of caution, if you do. Try this script out, and see what happens:
$true_value = true;
$false_value = false;
print ("true_value = " . $true_value);
print (" false_value = " . $false_value);
?>
What you should find is that the true_value will print "1", but the false_value won't print anything! Now replace true with 1 and false with 0, in the script above, and see what prints out.
Boolean values are very common in programming, and you often see this type of coding:
$true_value = true;
if ($true_value) {
print("that's true");
}
This is a shorthand way of saying "if $true_value holds a Boolean value of 1 then the statement is true". This is the same as:
if ($true_value = = 1) {
print("that's true");
}
The NOT operand is also used a lot with this kind of if statement:
$true_value = true;
if (!$true_value) {
print("that's true");
}
else {
print("that's not true");
}
Plublished by:
http://www.homeandlearn.co.uk/php/php3p11.html
Good Lucky!
Assinar:
Postar comentários (Atom)
Ok, but you forgot to mention the operators === and !==.
ResponderExcluir$true_value = 0;
if ($true_value === FALSE) {
// will not enter here
}
else {
// do stuff
}
Regards :)
Thanks for your help...i didnt know that..
ResponderExcluirIt means the value should be FALSE?