Operatori

Stefanescu Mihai 2 years ago PHP
Acest articol face parte din cursul Toate lectiile PHP. Te poti inscrie la acest curs aici!

Ce este un operator? Un raspuns cat se poate de simplu 4 + 6 = 9. Aici 4 si 5 sunt operanzi, iar + este operator.

PHP suporta urmatoprii operatori:

    • Operatori aritmetici
    • Operatori de comparatie
    • Operatori logici
    • Operatori de atribuire

Operatori conditionali (ternari)

Operatori Aritmetici

Presupunem ca A este 10 si B este 20

Operator Descriere Exemplu
+ Adunare A + B = 30
Scadere A – B = -10
* Inmultire A * B = 200
/ Impartire B / A = 2
% Modul B % A = 0
++ Incrementare A++ = 11
Decrementare A– = 9

Operatori de comparatie

Operator Descriere Exemplu
== Verifica o egalitate (A == B) va da FALSE
!= Verifica o inegalitate (A != B) va da TRUE
> Verifica daca valoarea din stanga este mai mare. (A > B) va da FALSE
< Verifica daca valoarea din dreapta este mai mare. (A < B) va da TRUE
>= Verifica daca valoarea din stanga este mai mare sau egala. (A >= B) va da FALSE
<= Verifica daca valoarea din dreapta este mai mare sau egala. (A <= B) va da TRUE

Operatori Logici

Operator Descriere Exemplu
AND Daca ambii operanzi sunt TRUE atunci rezultatul este TRUE (A AND B) va da TRUE
OR Daca unul dintre operanzi este TRUE atunci rezultatul este TRUE (A OR B) va da TRUE
&& Este exact ca AND.  
|| Este exact ca OR.  
! Acest operator se numeste NOT si este folosit pentru a inversa logica celorlalti operatori.Daca o conditie este TRUE atunci NOT o face FALSE !(A AND B) va da FALSE

Operatori de atribuire

Operator Descriere Exemplu
= Operator simplu de atribuire C = A + B inseamna ca C este egal cu rezultatul adunarii dintre A si B
+= Aduna operandul din stanga la cel din dreapta. C += A este echivalent cu C = C + A
-= Scade operandul din stanga din cel din dreapta C -= A este echivalent cu C = C – A
*= -//- C *= A este echivalent cu C = C * A
/= -//- C /= A este echivalent cu C = C / A
%= -//- C %= A este echivalent cu C = C % A

Operatori conditionali

Mai exista un operator numit operator conditional. Acesta evalueaza o expresia daca este TRUE sau FALSE si apoi executa una din doua coduri date in functie de rezultatul evaluarii.Exemplu:

<?php

$a = 10;

$b = ( ($a == 10)? "Da, a este 10":"Nu, a nu este 10");

//este similar cu:
if( $a == 10 ){
$b = "Da, a este 10";
}else{
$b = "Nu, a nu este 10";
}

 

Programator de ~8 ani, am lucrat la proiecte din mai multe industrstrii, de la eCommerce la telecomunicatii la automatizari. In acest timp am folosi diferite tehnologii, de la PHP, MySQL, PostgreSql, RabbitMq, Redis, Memcached si altele.


Get in touch
Pentru nelamuriri, dubii, comentarii si chestii de pe suflet ne putem auzi pe Discord, Reddit sau poti deschide o discutie noua pe forum

Gakvuz # 1 month ago buy fenofibrate without prescription <a href="https://fenoficor.com/">cheap tricor 200mg</a> tricor 160mg canada
Uljjxf # 1 month ago cheap zaditor 1 mg <a href="https://flixitorp.shop/">order zaditor generic</a> order tofranil 25mg generic
Xgwjlp # 1 month ago buy generic precose <a href="https://micronide.shop/">repaglinide usa</a> purchase fulvicin generic
Dunvyu # 4 weeks ago where can i buy aspirin <a href="https://aminirin.shop/">aspirin medication</a> cheap imiquad
Zxdrmq # 3 weeks ago dydrogesterone 10mg ca <a href="https://janozin.shop/">buy forxiga 10mg sale</a> buy empagliflozin medication
Lauri # 3 weeks ago Thanks designed for sharing such a nice idea, piece of writing is fastidious, thats why i have read it completely
Rtcwbb # 3 weeks ago buy cheap generic florinef <a href="https://acipolax.com/">order generic rabeprazole</a> order loperamide 2 mg without prescription
Uwwrzh # 2 weeks ago monograph 600 mg us <a href="https://colotazol.shop/">buy cilostazol no prescription</a> pletal 100 mg pills
Zctlav # 2 weeks ago order prasugrel 10mg without prescription <a href="https://thoramine.shop/">dramamine 50mg ca</a> order detrol 1mg online cheap
Angrvr # 2 weeks ago ferrous sulfate 100 mg for sale <a href="https://betaotec.com/">purchase sotalol sale</a> buy betapace 40mg online cheap
Vkufhe # 2 weeks ago pyridostigmine canada <a href="https://mestien.com/">mestinon canada</a> buy generic rizatriptan
sebifin zu einem hohen Preis ohne Rezept # 2 weeks ago Your style is very unique in comparison to other people I have read stuff from. I appreciate you for posting when you've got the opportunity, Guess I'll just bookmark this site.
Medikamentenpreis in Belgien # 2 weeks ago Usually I do not read article on blogs, but I would like to say that this write-up very forced me to take a look at and do it! Your writing style has been surprised me. Thank you, quite nice article.
crmozon # 2 weeks ago <a href="https://www.cagataycatal.net/england-away-vapor-nhlbg">england away vapor</a> <a href="https://www.karunasoap.com/tampa-bay-buccaneers-heart-soul-nfl-t-shirt-white-nflk">tampa bay buccaneers heart soul nfl t shirt white</a> <a href="https://www.hotelruf.net/pink-coach-purse-small-bagpl">pink coach purse small</a> <a href="https://www.kaasajans.com/toronto-blue-jays-hat-47-brand-equity-capr">toronto blue jays hat 47 brand equity</a> <a href="https://www.chargefirst.net/polo-ralph-lauren-outlet-online-usa-polodk">polo ralph lauren outlet online usa</a> <a href="https://www.nikknack.com/new-balance-995-womens-skod">new balance 995 womens</a> [url=http://www.crmozon.com/]crmozon[/url]
Qxurtr # 2 weeks ago buy vasotec 10mg pills <a href="https://casosin.com/">purchase casodex</a> lactulose over the counter
Xqudil # 1 week ago zovirax price <a href="https://aelimax.shop/">latanoprost over the counter</a> cost rivastigmine 3mg
Kvuils # 1 week ago order betahistine sale <a href="https://haloatan.com/">haloperidol 10 mg generic</a> buy benemid online cheap
pharmacie en ligne pour acheter albuterol en France # 1 week ago This is really interesting, You are a very skilled blogger. I have joined your feed and look forward to seeking more of your magnificent post. Also, I have shared your site in my social networks!
Uofdil # 1 week ago order micardis 20mg <a href="https://molnenil.shop/">brand molnupiravir 200mg</a> molnupiravir generic
Krbklc # 5 days ago order generic cenforce 100mg <a href="https://enapocen.com/">buy cenforce 50mg pills</a> cost aralen
isotretinoin 40 mg sans effets secondaires nocifs # 3 days ago This is my first time pay a quick visit at here and i am in fact happy to read all at one place.
venta de anquin en línea en España # 2 days ago This site was... how do you say it? Relevant!! Finally I have found something which helped me. Cheers!
kup evista bez recepty w Kaliszu # 2 days ago You've made some really good points there. I checked on the internet to find out more about the issue and found most people will go along with your views on this site.
Club-ul este dedicat membrilor si ofera access la mai multe zone ale website-ului.
Login Register

🔖 Bookmarks ➕
✨ Pentru a sustine aceasta comunitate am sa te rog sa te autentifici sau sa te inregistrezi!

🌪️ Discord ➕
Back to top
Folosim cookie-uri pentru a oferi functionalitatile critice ale aplicatiei Invata-Programare. Folosim cookie-uri si pentru a analiza traficul, pentru care e nevoie de consimtamantul dvs. explicit.