Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Różnica zapisie warunku if()
kari
post 23.08.2011, 06:53:34
Post #1





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 1.03.2005

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


Mam takie pytanie. Jaka jest różnica w takim zapytaniu:
  1. if () {
  2. echo 'wiadomość';
  3. }

a takim:
  1. if () echo 'wiadomość';
?
Czy ta druga wersja jest poprawna?


--------------------
(\.../)
(O.o)
(> <)
This is Bunny. Copy Bunny into your signature to help him on his way to world domination.
Go to the top of the page
+Quote Post
nospor
post 23.08.2011, 07:05:48
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Przecież masz to w manualu opisane :/
http://pl2.php.net/manual/en/control-structures.if.php
Cytat
Often you'd want to have more than one statement to be executed conditionally. Of course, there's no need to wrap each statement with an if clause. Instead, you can group several statements into a statement group. For example, this code would display a is bigger than b if $a is bigger than $b, and would then assign the value of $a into $b:
<?php
if ($a > $b) {
echo "a is bigger than b";
$b = $a;
}
?>


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
nekomata
post 23.08.2011, 07:21:20
Post #3





Grupa: Zarejestrowani
Postów: 314
Pomógł: 44
Dołączył: 12.11.2010
Skąd: UK

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


Albo skrócony syntax if'a ... bardzo przydatny jeśli mamy zamiar tylko jedną rzecz umieścić .
  1. <?php
  2. $boolean = false;
  3. $string = "STRING";
  4. $int = 4;
  5. echo $boolean ? 'true' : 'false';
  6. echo "\n";
  7. // albo z użyciem funkcji
  8. echo (is_string($string)) ? 'Tutaj if ' : 'A tu jest else' ;
  9. echo "\n";
  10. // Albo bez echa wykonywanie funkcji
  11. (is_int($int)) ? print($int) : print('Nie jest liczbą') ;
  12. ?>


Ten post edytował nekomata 23.08.2011, 07:21:50
Go to the top of the page
+Quote Post
Daiquiri
post 23.08.2011, 07:43:51
Post #4





Grupa: Administratorzy
Postów: 1 552
Pomógł: 211
Dołączył: 7.07.2009
Skąd: NJ




Nekomata proszę, darujmy sobie przepisywanie manuala i książek...
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 08:11