Array-uri (Vectori)

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

Un array (vector) reprezinta o succesiune de elemente sub forma de perechi cheie -> valoare, unde fiecare cheie identifica in mod unic un element.Spre deosebire de alte limbaje unde cheia trebuia sa fie numerica, in PHP cheia poate fi atat numerica cat si string, iar valorile din array pot avea orice tip de date.In PHP exista 3 tipuri de array-uri:

  • Array-uri numerice – Un array cu chei numerice. Valorile sunt stocate si accesate intr-un mod linearArray-uri Asociative – Un array cu chei string-uri.  Valorile sunt accesate dupa cheie si nu intr-un mod linear ca mai sus.Array-uri multidimensionale – Un array care are pe post de valoare unul sau mai multe array-uri.

Array-uri Numerice

Acest tip de array-uri pot stoca numere, stringuti sau obiecte, dar cheile lor trebuie sa fie numeric. In mod normal indexul incepe de la 0.

/* O metoda de e creea un array. */
$numere = array( 1, 2, 3, 4, 5);
foreach( $numere as $valoare ){
  echo "Valoarea este $valoare <br />";
/* A doua metoda. */
$numere[0] = "unu";
$numere[1] = "doi";
$numere[2] = "trei";
$numere[3] = "patru";
$numere[4] = "cinci";

foreach( $numere as $valoare ){
  echo "Valoarea este $valoare <br />";

Array-uri Asociative

Array-urile asociative sunt similare cu array-urile numerice, singura diferenta fiind indexul (cheia).

$cumparaturi = array( 
				"Paine" => 3,
				"Lapte" => 1,
				"Oua" => 12
echo "Lista mea de cumparaturi:";				
foreach( $cumparaturi as $cheie -> $valoare ){
  echo "$cheie - ".$valoare[$cheie]." <br />";
//Codul de mai sus este similar cu acesta:
echo "Lista mea de cumparaturi:";				
	echo $cumparaturi['Paine']."<br/>";
	echo $cumparaturi['Lapte']."<br/>";
	echo $cumparaturi['Oua']."<br/>";

Array-uri multidimensionale

Un array multidimensional este un array care are una sau mai multe valori array (Puteti sa va duceti cu gandul la matrici(matematica cls XI-XII) ).

$filme_preferate = array(
			"Actiune" => array(
						"Bad Company"
			"Comedie" => array(
						"Almost Heroes"
			"Drama" => array(
						"12 Angry Men",
						"25th Hour",
						"88 Minutes"


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

women's organic supplements for hormonal balance # 6 months ago hormone supplements for women's sleep over the counter hormone therapy prices online menopause organic supplements for vaginal dryness cost where to buy hormone supplements in the usa
experience the ultimate relaxation # 5 months ago Hello everyone, it's my first pay a quick visit at this web page, and post is actually fruitful in favor of me, keep up posting such content.
acheter minomycin 50 mg en Suisse # 1 month ago Hi, after reading this awesome article i am as well delighted to share my knowledge here with friends.
Nhmcmg # 1 month ago fenofibrate 160mg pills <a href="">tricor 160mg for sale</a> order generic tricor 200mg
Ggtbkp # 1 month ago ketotifen ca <a href="">order imipramine 75mg</a> imipramine 25mg us
Vbefqc # 1 month ago minoxytop medication <a href="">order tamsulosin 0.4mg online cheap</a> new ed drugs
Khfvqh # 1 month ago buy generic acarbose for sale <a href="">cost micronase 2.5mg</a> order griseofulvin 250 mg online cheap
Tabtwh # 1 month ago order aspirin 75 mg pill <a href="">buy levoflox no prescription</a> oral zovirax
Jhklqr # 3 weeks ago order duphaston sale <a href="">duphaston 10mg cheap</a> order empagliflozin online
provera sans prescription en Europe # 3 weeks ago I know this web site offers quality depending articles or reviews and additional material, is there any other web site which offers these things in quality?
Alcmhp # 3 weeks ago where can i buy florinef <a href="">order imodium 2 mg generic</a> imodium for sale online
Lfsohy # 3 weeks ago buy monograph generic <a href="">pletal pills</a> cilostazol 100 mg for sale
Pyxlaw # 3 weeks ago prasugrel pill <a href="">thorazine 50 mg cheap</a> detrol 1mg sale
kaufe ortho-cept in der Schweiz # 2 weeks ago I am now not certain the place you're getting your information, but good topic. I needs to spend some time learning more or understanding more. Thanks for excellent info I used to be on the lookout for this information for my mission.
Punzie # 2 weeks ago buy ferrous 100 mg generic <a href="">ferrous 100mg over the counter</a> buy sotalol online
Xeblod # 2 weeks ago purchase mestinon without prescription <a href="">maxalt us</a> order rizatriptan for sale
evecalls # 2 weeks ago <a href=>maxx crosby white jersey</a><a href=>make your own nba jersey online</a><a href=>womens sixers apparel</a><a href=>miami heats new uniforms</a> <a href="">boston red sox ladies hats zillow</a> <a href="">ccm vintage jerseys for cheap</a> <a href="">pittsburgh pirates hat meaning xbox one</a><a href="">michael jordan fitted hats 90s</a><a href="">boston red sox dog hat 2017</a><a href="">hats dolphin mall nj</a> <a href="">air force 1 s black</a> <a href=>jordan 6 low white rot</a><a href=>jordan 13 og white black</a><a href=>nike air more uptempo bambini</a><a href=>adidas nmd ri maschio</a> [url=]evecalls[/url]
Medikamente mit oder ohne Rezept in Frankreich # 2 weeks ago I think that what you posted made a bunch of sense. However, what about this? what if you were to write a awesome title? I am not suggesting your information isn't good., but what if you added a post title that makes people desire more? I mean Array-uri (Vectori) - Invata-Programare is a little boring. You ought to look at Yahoo's front page and see how they create news titles to grab people interested. You might add a related video or a pic or two to grab people excited about everything've written. In my opinion, it could make your blog a little livelier.
Preise fรผr prometrium in Marokko # 2 weeks ago If you desire to grow your knowledge only keep visiting this web site and be updated with the most up-to-date news update posted here.
Kprrrf # 2 weeks ago buy generic vasotec 10mg <a href="">bicalutamide 50 mg pills</a> buy duphalac bottles for sale
Yxqqie # 1 week ago buy generic xalatan <a href="">buy generic xeloda</a> buy rivastigmine 6mg generic
Doaizi # 1 week ago betahistine 16 mg over the counter <a href="">order haloperidol 10mg without prescription</a> buy probenecid cheap
Tytjtf # 1 week ago order telmisartan 20mg pills <a href="">brand hydroxychloroquine 200mg</a> molnupiravir 200mg uk
Mitmhu # 6 days ago cenforce over the counter <a href="">oral naproxen 250mg</a> order aralen 250mg generic
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.