Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> 'string' == 0 => true?
DEXTER_c
post
Post #1





Grupa: Zarejestrowani
Postów: 58
Pomógł: 0
Dołączył: 8.12.2005

Ostrzeżenie: (0%)
-----


Czuję, że będzie to szczytowo głupie pytanie, ale nie mogę pojąć, dlaczego kod:

  1. <?php
  2. if('string' == 0) {
  3.  echo 'dziwne!';
  4. }
  5. ?>


Wyświetli komunikat, skoro przecież 'string' nie może się równać zero! (IMG:http://forum.php.pl/style_emoticons/default/blinksmiley.gif)

Wiem, że php traktuje zero jako false, ale:

  1. <?php
  2. if('string' == false) {
  3.  echo 'dziwne!';
  4. }
  5. ?>


Nie wyświetli komunikatu (IMG:http://forum.php.pl/style_emoticons/default/blinksmiley.gif)

Używam php 5.2.0, Apache 2, Linux 2.6.x

Ten post edytował DEXTER_c 27.01.2007, 12:26:42
Go to the top of the page
+Quote Post
dr_bonzo
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

Ostrzeżenie: (0%)
-----


'===' i wszystko jasne

przy
'string' == 0
chyba stringa zamienia na integera, czyli zero (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

no tak:
  1. <pre><?php
  2.  
  3. $string = 'costam';
  4. $string_as_int = intval( $string );
  5. $string_as_bool = (bool)( $string );
  6.  
  7. var_dump( $string );
  8. var_dump( $string_as_int );
  9. var_dump( $string_as_bool );
  10. ?></pre>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 18:10