Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

PHP type array

An array is an ordered map whose keys are integers or strings.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

array $items

An array is an ordered map whose keys are integers or strings. Lists are arrays with consecutive integer keys starting at zero. A canonical decimal string key such as "8" becomes integer 8, while "08" remains a string. Updating an existing key replaces its value without changing its position.

$items = ['8'=>'old', '08'=>'padded', 8=>'new'];
echo json_encode([array_keys($items), array_values($items)]);
[[8,"08"],["new","padded"]]

Examples

<?php
$items = ['8'=>'old', '08'=>'padded', 8=>'new'];
echo json_encode([array_keys($items), array_values($items)]);

Result

[[8,"08"],["new","padded"]]

Sources