167 of 410 menu

The array_fill_keys Function

The array_fill_keys function creates an array and fills it with elements of a specific value so that the entire array has the same elements, but different keys. The keys are taken from the array passed as the first parameter.

Syntax

array_fill_keys(array $keys, mixed $value): array

Example

Let's fill an array with elements containing the text 'x'. The keys for the new array will be passed as the first parameter:

<?php $res = array_fill_keys(['a', 'b', 'c'], 'x'); var_dump($res); ?>

Code execution result:

['a' => 'x', 'b' => 'x', 'c' => 'x']

See Also

  • the array_fill function,
    which fills an array with values without specified keys
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