Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Collections and array keys

A PHP array is an ordered map with int or string keys.

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

Syntax

$rows[$key] = $value; array_is_list($rows);

A PHP array is an ordered map with int or string keys. Assigning the same key replaces its value without moving the entry. A list has consecutive integer keys starting at zero in iteration order. Removing an interior element creates a gap until the values are reindexed.

$rows=["a","b","c"];unset($rows[1]);$rows[0]="A";echo json_encode([array_keys($rows),array_is_list($rows),array_values($rows)]);
[[0,2],false,["A","c"]]

Examples

<?php
$rows=["a","b","c"];unset($rows[1]);$rows[0]="A";echo json_encode([array_keys($rows),array_is_list($rows),array_values($rows)]);

Result

[[0,2],false,["A","c"]]

Sources