PHP 8 reference · Array Functions

PHP array_values() Function

Return all the values of an array as a list re-indexed from 0. Often used after array_filter() or unset().

PHP 8 Since 4.0

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array_values(array $array): array

Parameters

ParameterDescription
array The input array.

Return value

A list of the values.

Examples

Drop the keysTry it yourself
<?php
$user = ["name" => "Ada", "role" => "admin"];
print_r(array_values($user));

Output

Array
(
    [0] => Ada
    [1] => admin
)
Renumber after unset()Try it yourself
<?php
$list = ["a", "b", "c"];
unset($list[1]);
echo json_encode($list), "\n";
echo json_encode(array_values($list)), "\n";

Output

{"0":"a","2":"c"}
["a","c"]

Version history

VersionChange
PHP 4.0Added

In other languages

Was this page helpful?