Website Development Prices

Search Blog

Friday, October 23, 2015

Logicki operatori (Logical operators)

Ako zelite da budete sigurni da je temperatura veca od 65 i manja od 70, mozete upotrebiti ugnjezden iskaz if.

<?php

$temperatura = 66;
if ($temperatura > 65) {
if ($temperatura < 70) {
echo "Temperatura je prijatna.";
}
}


?>

Rezultat: Temperatura je prijatna.

Postoji i jednostavniji nacin. Mozete da koristite logicki operator && (And) i da njime povezete uslove $temperatura > 65 and $temperatura < 70. U ovom slucaju oba uslova moraju biti tacna da bi se izvrsio iskaz if


$temperatura = 66;
if ($temperatura > 65 && $temperatura < 70) {
echo "Temperatura je prijatna.";
}


?>

Prethodni kod stavite pod komentar pa dodajte ovaj.

Rezultat: Temperatura je prijatna.

Ovde ste uslove $temperatura > 65 i $temperatura < 70 povezali preko operatora &&. Oba uslova moraju biti tacna da bi ceo izraz bio tacan.

U tabeli koja sledi data je lista svih logickih operatora u PHP-u.



If you want to be sure that the temperature is greater than 65 and less than 70, you can use nested if statement.

$temperature = 66;
if ($temperature > 65) {
if ($temperature < 70) {
echo "The temperature is pleasant.";
}
}

Result: The temperature is pleasant.

There is a simpler way. You can use logical operator && (And) to connect conditions $temperature > 65 and $temperature < 70. In this case, both conditions must be true in order to perform if statement.

$temperature = 66;
if ($temperature > 65 && $temperature < 70) {
echo "The temperature is pleasant.";
}

Comment previous code and add this.

Result: The temperature is pleasant.

Here, the conditions $temperature > 65 and $temperature < 70 you connected over operator &&. Both conditions must be true so the entire expression can be true.

The table below shows a list of all the logical operators in PHP.



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.