|
użytkowników online: 13
|
|
OPINIE UŻYTKOWNIKÓW
|
O wysokich kompetencjach zawodowych Darka nie ma co dyskutować. Wszyscy chyba jesteśmy zgodni co do tego, że Jego wiedza na polu informatycznym jest bogata i zasługuje na uznanie. Swego czasu zwróciłem się z prośbą o pomoc w realizacji małego projektu internetowego. Projekt był niewielki, jednak jego realizacja wymagała pewnego doświadczenia. Darek podjął się tego zlecenia, wykonał je szybko i sprawnie. Podczas realizacji służył doradztwem, jednak w żaden sposób nie narzucał swojego zdania. O prawidłowości Jego koncepcji przekonałem się dopiero po pewnym czasie. To, czego ja nie dostrzegałem, On dostrzegał i zwracał na to moją uwagę. Darek dał się poznać nie tylko, jako dobry fachowiec, co przede wszystkim okazał się być rzetelnym i uczciwym kontrahentem. Tak więc nie dość, że fachowiec, to jeszcze uczciwy. Polecam usługi Darka wszystkim tym, którzy szukają fachowej pomocy przy realizacji nawet najbardziej złożonych projektów.
Dariusz Żwan
Actuarius.pl
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
Ten rodzaj jest najprostszy. Typ boolean wyraża logiczną
prawdę lub fałsz. Może mieć wartości TRUE lub FALSE.
Notatka:
Typ boolowski został wprowadzony w PHP 4.
Aby utworzyć wartość boolowską, należy użyć słów kluczowych TRUE lub
FALSE. Wielkość liter w tych słowach nie gra roli.
Ten typ najczęściej używany jest przy
operatorach, które zwracają
wartość typu boolean, którą następnie przekazuje się
do struktur kontrolnych.
Aby jawnie skonwertować wartość na typ boolean, należy
użyć rzutowania (bool) lub
(boolean). Jednakże w większości przypadków nie ma
potrzeby użycia rzutowania, ponieważ wartość będzie automatycznie
skonwertowana na typ boolean, jeśli operator, funkcja lub
struktura kontrolna wymaga argumentu tego właśnie typu.
Zobacz też
wykorzysytwanie typów
danych.
Przy konwersji na typ boolean, poniższe wartości otrzymują
wartość logiczną FALSE:
Każda inna wartość otrzymuje logiczną wartość TRUE (włączając w to
identyfikatory zasobów).
| Ostrzeżenie |
-1 także ma wartość TRUE, jak każda niezerowa
(ujemna lub dodatnia) liczba!
|
User Contributed Notes25-Jan-2006 01:00
Just a supplement to johnjc-phpdoc's post:
This
if ( strpos($needle,$haystack) !== false )
is not the same as
if (!strpos($needle,$haystack) === false )
for the reason he states, namely, strpos does not evaluate to true, ever.
johnjc-phpdoc at publicinfo dot net
01-Nov-2005 06:38
The === and !== are not fully documented in either the Comparison Operator or Booleans type sections. They are talked about a bit more in the sections on strpos() and array_search() but they refer you to the section on Booleans for further information.
I am putting my contribution on === and !== in the Booleans section with pointers to it from the comment areas of other sections.
This refers only to the use of === and !== with functions like strpos() and array_search() which may a needle at character 0 in a string or element 0 in an array. Because the 0 returned by the function evaluates to == 'false' === and !== are used. You can say
<?php if ( strpos($needle,$haystack) !== false ) { print "found it\n"; } ?>
and you can say
<?php if ( strpos($needle,$haystack) === false ) { print "didn't find it\n"; } ?>
but you cannot say
<?php if ( strpos($needle,$haystack) === true ) { print "found it \n"; } ?>
nor can you say
<?php if ( strpos($needle,$haystack) !== true ) { print "didn't find it\n"; } ?>
This is because strpos() and array_search do not return 'true' when successful and the numbers they return do not evaluate to === true. So you cannot use 'true' in any way with these functions.
I frequently find myself adding string elements to an array as I find them and using the growing array as my record of what has already been done such as
<?php if ( array_search($needle,$haystack) !== false ) { print "done one of those already\n"; } ?>
or
<?php if ( array_search($needle,$haystack) === false ) { print "got a new one\n"; array_push($haystack,$needle) } ?>
The more natural way to say this would have been the other way around:
<?php if ( array_search($needle,$haystack) === true ) { print "done one of those already\n"; } ?>
or
<?php if ( array_search($needle,$haystack) !== true ) { print "got a new one\n"; array_push($haystack,$needle) } ?>
because you don't go around saying, "if this is not false", you say "if this is true".
But that won't work. Now I've had it explained to me it makes sense that the function doesn't return 'true' because it returns a number value instead. And given that === checks the type you can't have the number evaluate to '=== true'. But the result for the user of PHP is counter-intuitive and so deserves specific documenting.
x123 (at) bestof (dash) inter (dot) net
15-Nov-2004 09:24
another correction to the preceding "correction":
"as the documention states" is right,
"any non-empty string is true" is wrong : (bool) "0" === false !
(but "00" and "0.0" etc. are true!)
So watch out, you can NOT test for non-empty strings using e.g.
<?php
if (is_string($s))
if ($s) echo " '$s' is a non-empty string";
else echo " '$s' is an empty string"; else echo " $s is not a string ";
?>
indeed, for $s='0' this would print: " '0' is an empty string"
which is wrong, of course.
This is particularly "dangerous" in connection with MySQL
which prints FALSE by default as 0,
which comes back from a FORM POST as string '0',
while PHP prints FALSE as empty string (!);
a similar problem is to preserve a NULL value through a FORM post....
adama at NO-UBE dot augustinefam dot org
23-May-2003 07:13
Just a correction to the 29-Apr-2003 10:49 posting. The first section of the comment, where
$myBool = true ; print( $myBool ) ;
is indistinguishable from
print( "" ) ;
likewise,
$myBool = false ; print( $myBool ) ;
is indistinguishable from
print( 1 ) ;
is backwards. It should actually be
$myBool = true ; print( $myBool ) ;
is indistinguishable from
print( 1 ) ; //corrected
likewise,
$myBool = false ; print( $myBool ) ;
is indistinguishable from
print( "" ) ; //corrected
The posting makes a good point, though. Don't expect the contents of a string to mean something special. As the documentation states, any non-empty string is true, including "false" since it is simply a non-empty string.
|