array_values
Returns the values of an array with keys numbered from zero.
Syntax
array_values(array $array): arrayParameters
| Parameter | Type | Description |
|---|---|---|
| $array | array | The source array. |
Return value
arrayA list of the values.
Examples
The values of an associative array:
<?php
echo implode(', ', array_values(['name' => 'Anna', 'city' => 'London']));Output:
Anna, LondonRenumbering after filtering:
<?php
$big = array_filter([5, 12, 8, 20], fn ($n) => $n > 10);
echo json_encode($big), "\n";
echo json_encode(array_values($big));Output:
{"1":12,"3":20}
[12,20]Notes
array_filter() and array_unique() keep the original keys. array_values() removes the gaps in the numbering.
See also
- array_keys — Returns all the keys of an array.
- array_filter — Keeps the array elements that pass a test.
Related recipes
In the tutorial
- Array functions — Processing arrays in PHP without loops — array_map, array_filter, array_reduce, searching and slicing.