Samouczek PHP

Strona główna PHP Wprowadzenie do PHP Instalacja PHP Składnia PHP Komentarze PHP Zmienne PHP PHP Echo / Drukuj Typy danych PHP Ciągi PHP Liczby PHP Matematyka w PHP Stałe PHP Operatory PHP PHP Jeśli...Inne...Elseif Przełącznik PHP Pętle PHP Funkcje PHP Tablice PHP PHP Superglobals PHP RegEx

Formularze PHP

Obsługa formularzy PHP Walidacja formularzy PHP Wymagany formularz PHP Adres URL/e-mail formularza PHP Formularz PHP kompletny

Zaawansowany PHP

Data i godzina w PHP Uwzględnij PHP Obsługa plików PHP Otwórz/odczytaj plik PHP Tworzenie/zapisywanie plików PHP Przesyłanie plików PHP Pliki cookie PHP Sesje PHP Filtry PHP Zaawansowane filtry PHP Funkcje wywołania zwrotnego PHP PHP JSON Wyjątki PHP

PHP OOP

PHP Co to jest OOP Klasy/obiekty PHP Konstruktor PHP Destruktor PHP Modyfikatory dostępu PHP Dziedziczenie PHP Stałe PHP Klasy abstrakcyjne PHP Interfejsy PHP Cechy PHP Metody statyczne PHP Właściwości statyczne PHP Przestrzenie nazw PHP Iterowalne PHP

Baza danych MySQL

Baza danych MySQL Połączenie MySQL Tworzenie bazy danych MySQL Utwórz tabelę MySQL Wstaw dane MySQL Pobierz ostatni identyfikator MySQL Wstaw wiele MySQL Przygotowano MySQL Wybierz dane MySQL MySQL Gdzie Zamów MySQL według Usuń dane MySQL Dane aktualizacji MySQL Dane limitu MySQL

PHP XML

Parsery PHP XML Parser PHP SimpleXML PHP SimpleXML — Get Rozszerzenie PHP XML PHP XML DOM

PHP - AJAX

Wprowadzenie do AJAX AJAX PHP Baza danych AJAX XML AJAX Wyszukiwanie na żywo AJAX Ankieta AJAX

Przykłady PHP

Przykłady PHP Kompilator PHP Quiz PHP Ćwiczenia PHP Certyfikat PHP

Odniesienie do PHP

Przegląd PHP Tablica PHP Kalendarz PHP Data PHP Katalog PHP Błąd PHP Wyjątek PHP System plików PHP Filtr PHP PHP FTP PHP JSON Słowa kluczowe PHP Biblioteka PHP Poczta PHP Matematyka w PHP Różne PHP PHP MySQLi Sieć PHP Kontrola wyjścia PHP PHP RegEx PHP SimpleXML Strumień PHP ciąg PHP Obsługa zmiennych PHP Parser PHP XML Kod pocztowy PHP Strefy czasowe PHP

Operatory PHP


Operatory PHP

Operatory służą do wykonywania operacji na zmiennych i wartościach.

PHP dzieli operatory na następujące grupy:

  • Operatory arytmetyczne
  • Operatorzy przypisania
  • Operatory porównania
  • Operatory inkrementacji/dekrementacji
  • Operatory logiczne
  • Operatory ciągów
  • Operatory tablicowe
  • Operatory przypisania warunkowego

Operatory arytmetyczne PHP

Operatory arytmetyczne PHP są używane z wartościami numerycznymi do wykonywania typowych operacji arytmetycznych, takich jak dodawanie, odejmowanie, mnożenie itp.

Operator Name Example Result Show it
+ Addition $x + $y Sum of $x and $y
- Subtraction $x - $y Difference of $x and $y
* Multiplication $x * $y Product of $x and $y
/ Division $x / $y Quotient of $x and $y
% Modulus $x % $y Remainder of $x divided by $y
** Exponentiation $x ** $y Result of raising $x to the $y'th power

Operatory przypisania PHP

Operatory przypisania PHP są używane z wartościami liczbowymi do zapisywania wartości do zmiennej.

Podstawowym operatorem przypisania w PHP jest „=”. Oznacza to, że lewy operand zostaje ustawiony na wartość wyrażenia przypisania po prawej stronie.

Assignment Same as... Description Show it
x = y x = y The left operand gets set to the value of the expression on the right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus


Operatory porównania PHP

Operatory porównania PHP służą do porównywania dwóch wartości (liczby lub łańcucha):

Operator Name Example Result Show it
== Equal $x == $y Returns true if $x is equal to $y
=== Identical $x === $y Returns true if $x is equal to $y, and they are of the same type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y Returns true if $x is not equal to $y, or they are not of the same type
> Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y
<= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y
<=> Spaceship $x <=> $y Returns an integer less than, equal to, or greater than zero, depending on if $x is less than, equal to, or greater than $y. Introduced in PHP 7.

Operatory inkrementacji / dekrementacji PHP

Operatory inkrementacji PHP są używane do inkrementacji wartości zmiennej.

Operatory dekrementacji PHP są używane do dekrementacji wartości zmiennej.

Operator Name Description Show it
++$x Pre-increment Increments $x by one, then returns $x
$x++ Post-increment Returns $x, then increments $x by one
--$x Pre-decrement Decrements $x by one, then returns $x
$x-- Post-decrement Returns $x, then decrements $x by one

Operatory logiczne PHP

Operatory logiczne PHP służą do łączenia instrukcji warunkowych.

Operator Name Example Result Show it
and And $x and $y True if both $x and $y are true
or Or $x or $y True if either $x or $y is true
xor Xor $x xor $y True if either $x or $y is true, but not both
&& And $x && $y True if both $x and $y are true
|| Or $x || $y True if either $x or $y is true
! Not !$x True if $x is not true

Operatory ciągów PHP

PHP ma dwa operatory, które są specjalnie zaprojektowane dla łańcuchów.

Operator Name Example Result Show it
. Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2
.= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1

Operatory tablic PHP

Operatory tablicowe PHP są używane do porównywania tablic.

Operator Name Example Result Show it
+ Union $x + $y Union of $x and $y
== Equality $x == $y Returns true if $x and $y have the same key/value pairs
=== Identity $x === $y Returns true if $x and $y have the same key/value pairs in the same order and of the same types
!= Inequality $x != $y Returns true if $x is not equal to $y
<> Inequality $x <> $y Returns true if $x is not equal to $y
!== Non-identity $x !== $y Returns true if $x is not identical to $y

Operatory warunkowego przypisania PHP

Operatory warunkowego przypisania PHP służą do ustawiania wartości w zależności od warunków:

Operator Name Example Result Show it
?: Ternary $x = expr1 ? expr2 : expr3 Returns the value of $x.
The value of $x is expr2 if expr1 = TRUE.
The value of $x is expr3 if expr1 = FALSE
?? Null coalescing $x = expr1 ?? expr2 Returns the value of $x.
The value of $x is expr1 if expr1 exists, and is not NULL.
If expr1 does not exist, or is NULL, the value of $x is expr2.
Introduced in PHP 7

Ćwiczenia PHP

Sprawdź się za pomocą ćwiczeń

Ćwiczenie:

Pomnóż 10przez 5i wypisz wynik.

echo 10  5;