⊗ppPmMdAs 134 of 447 menu

Associative Arrays in PHP

Multidimensional arrays can also be associative, for example, like this:

<?php $arr = [ 'user1' => [ 'name' => 'name1', 'age' => 31, ], 'user2' => [ 'name' => 'name2', 'age' => 32, ], ]; ?>

Let's use this array to display, for example, the name of the second user:

<?php echo $arr['user2']['name']; // will output 'name2' ?>

Given the following array:

<?php $arr = [ 'boys' => [1 => 'John', 2 => 'Jack', 3 => 'Ryan'], 'girls' => [1 => 'Emma', 2 => 'Lily', 3 => 'Anna'], ]; ?>

Using this array, output the name of the first boy and the name of the second girl.

Given the following array:

<?php $arr = [ [ 'name' => 'user1', 'age' => 30, 'salary' => 1000, ], [ 'name' => 'user2', 'age' => 31, 'salary' => 2000, ], [ 'name' => 'user3', 'age' => 32, 'salary' => 3000, ], ]; ?>

Using this array, output the sum of the salaries of the first and third user.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline