Hi everyone! I'm the author of code.mu :)
I'd love to chat with my non-Russian audience. I'm looking for your feedback on the site and the translation quality. Let's chat:)
⊗ppPmArERe 61 of 447 menu
◀ ▶

Overwriting Array Elements in PHP

You can also read the current value of an element, perform some operations with it, and write the changed value back into this element:

<?php $arr = ['a', 'b', 'c']; $arr[0] = $arr[0] . '!'; $arr[1] = $arr[1] . '!'; $arr[2] = $arr[2] . '!'; var_dump($arr); // will output ['a!', 'b!', 'c!'] ?>

The previous code can be rewritten using the .= operator:

<?php $arr = ['a', 'b', 'c']; $arr[0] .= '!'; $arr[1] .= '!'; $arr[2] .= '!'; var_dump($arr); // will output ['a!', 'b!', 'c!'] ?>

Given the following array:

<?php $arr = ['a' => 1, 'b' => 2, 'c' => 3]; ?>

Add the number 3 to each element of the array. Display the modified array on the screen.

← →
↑
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