Website Development Prices

Pretrazite Blog // Search This Blog

Showing posts with label PHP operatori (PHP operators). Show all posts
Showing posts with label PHP operatori (PHP operators). Show all posts

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

Sunday, October 11, 2015

Operatori poredjenja deo 2 (Comparison operators part 2)

Sa iskazom if se koristi citav niz operatora. To su operatori poredjenja. Oni omogucavaju da se porede dve vrednosti. 

U prethodnom clanku su dati svi operatori poredjenja koji postoje u PHP-u.

Ako zelite da proverite da li je vrednost promenljive $temperatura bila tacno 65 stepeni, mozete upotrebiti operator jednokosti ==.

Primer:

<?php

$temperatura = 65;

if ($temperatura == 65) {
echo "Danas je 65 stepeni.";
}

?>

Ovaj fajl sacuvajte kao operatori-poredjenja.sql.

Rezultat: Danas je 65 stepeni.

Thursday, October 8, 2015

Operatori poredjenja (Comparison operators)

OPERATOR        OPERACIJA                   PRIMER            

==          jednako                            $a == $b         

REZULTAT tacno ako je $a jednako sa $b

===         identicno          $a === $b         
REZULTAT tacno ako je $a jednako sa $b i ako su istog tipa

!=          razlicito                            $a != $b            
REZULTAT tacno ako $a nije jednako sa $b

<>          razlicito                            $a <> $b          
REZULTAT tacno ako $a nije jednako sa $b

!==         nije identicno                 $a !== $b          
REZULTAT tacno ako $a nije jednako sa $b ili ako nisu istog tipa

<           manje od          $a < $b      
REZULTAT tacno ako je $a manje od $b

>           vece od                            $a > $b               
REZULTAT tacno ako je $a vece od $b

<=          manje ili jednako          $a <= $b         
REZULTAT tacno ako je $a manje ili jednako od $b

>=                     vece ili jednako              $a >= $b         
REZULTAT tacno ako je $a vece ili jednako od $b



Operator           Operation                           Example            

==                      Equal to                              $a == $b           
Result true if $a is equal to $b

===                    Identical                             $a === $b         
Result true if $a is equal to $b and if they  are same type

! =                      Different                              $a! = $b             
Result true if $a is not equal to $b

<>                     Differently and                    $a <> $b           
Result true if $a is not equal to $b

! ==                   Not identical                       $a! == $b          
Result true if $a is not equal to $b or if they are not of the same type

<                       Less than                              $a < $b               
Result true if $a is less than $b

>                     Greater than                        $a > $b               
Result true if $a is bigger than $b

<=                    Less or equal to                   $a <= $b            
Result true if $a is less than or equal to $b

> =             Greater than or equal to     $a> = $b          
Result true if $a is greater than or equal to $b

Wednesday, September 16, 2015

Operatori za rad sa stringovima (Operators for work with strings)

U PHP-u postoje dva operatora za rad sa stringovima:

  • operator konkatenacije (.)
  • operator spajanja i dodele (.=)
Prvi operator spaja operande sa leve i desne strane u jedan string. 

Drugi operator dodaje operand sa desne strane operandu sa leve strane.

Primer:

<?php

$motori = "Ja volim ";

echo "\$motori = ", $motori, "<br>";
echo "\$plavi = \$motori . \"plavi\"<br>";

$plavi = $motori . "plavi ";
echo "motor \$plavi = ", $plavi, "<br>";
echo "\$plavi .= \"Suzuki.\"<br>";

$plavi .= "Suzuki.";
echo "motor \$plavi = ", $plavi, "<br>";

?>

Ovaj fajl sacuvajte kao operatori-za-stringove.php.

Rezultat:

$motori = Ja volim
$plavi = $motori . "plavi"
motor $plavi = Ja volim plavi
$plavi .= "Suzuki."
motor $plavi = Ja volim plavi Suzuki.


In PHP, there are two operators to work with strings:

  • concatenation operator (.)
  • concatenating assignment operator (. =)

The first operator connects the operands on the left and right side in a single string.

Another operator adds operand from the right to operand on the left.

Example:

<?php

$motobikes = "I love ";

echo "\$motobikes = ", $motobikes, "<br>";
echo "\$blue = \$motobikes . \"blue\"<br>";

$blue = $motobikes . "blue ";
echo "motobike \$blue = ", $blue, "<br>";
echo "\$blue .= \"Suzuki.\"<br>";

$blue .= "Suzuki.";
echo "motobike \$blue = ", $blue, "<br>";

?>

Save this file as operators-forstrings.php.

Result:

$motobikes = I love
$blue = $motobikes . "blue"
motobike $blue = I love blue
$blue .= "Suzuki."
motobike $blue = I love blue Suzuki.


Tuesday, June 9, 2015

Prioritet operatora (Operators Priority)

Ako se u istom trenutku koristi vise operatora, koji se koristi prvi?

Primer:

<?php
     echo "4 + 2 * 9";
?>

Ovaj fajl sacuvajte kao prioritet-operatora.php.

Da li ce prvo izracunati deo sa operatorom +, tako da se dobije 4+2*9=6*9=54 ili ce se prvo izracunati deo sa operatorom *, tako da se dobije 4+2*9=4+28=22?

Odgovor je 22. Zato sto operator * ima prioritet nad operatorom +.

Ako prioritet operatora nije u skladu sa onim sto zelite, mozete da upotrebite zagrade. 

Ako izraz promenite na (4+2)*9, dobicete 6*9=54. 

Primer:

<?php
echo "4 + 2 * 9 = ", 4 + 2 * 9, "<br>"; // R: 4 + 2 * 9 = 22
echo "(4 + 2) * 9 = ", (4 + 2) * 9, "<br>"; // R: (4 + 2) * 9 = 54
echo "4 + (2 * 9) = ", 4 + (2 * 9), "<br>"; //R: 4 + (2 * 9) = 22

?>

If at the same time you are using multi operator, which one to use first?

Example:

<?php
     echo "4 + 2 * 9";
?>

This file save as priority-operators.php.

To calculate which operator will be first used, operator +, so that you get 4 + 2 = 6 * 9 * 9 = 54, or it will be used the first operator *, so that you get 4 + 2 = 4 * 9 + 28 = 22?

Answer is 22. Because the operator * has priority over the operator +..

If operator precedence is not in line with what you want, you can use parentheses.

If you change the expression (4 + 2) * 9, you will get 6 * 9 = 54.


Example:

<?php
echo "4 + 2 * 9 = ", 4 + 2 * 9, "<br>"; // R: 4 + 2 * 9 = 22
echo "(4 + 2) * 9 = ", (4 + 2) * 9, "<br>"; // R: (4 + 2) * 9 = 54
echo "4 + (2 * 9) = ", 4 + (2 * 9), "<br>"; //R: 4 + (2 * 9) = 22

?>

Search Blog

Price za decu