Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

array_values()

Discard the original keys and return a list of values in iteration order, indexed from zero.

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

Syntax

array_values(array $array): array

Discard the original keys and return a list of values in iteration order, indexed from zero. This can turn a filtered sparse sequence into a JSON list. Any identity encoded in the former keys is lost in the result, while the original array keeps those keys.

Signature

array_values(array $array): array

Example output

[["A","B"],[3,8]]

Examples

<?php
$sparse = [3=>'A', 8=>'B'];
echo json_encode([array_values($sparse), array_keys($sparse)]);

Result

[["A","B"],[3,8]]

Sources