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
Syntax
array_values(array $array): array
Parameters
| Parameter | Description |
|---|---|
array |
The input array. |
Return value
A list of the values.
Examples
<?php
$user = ["name" => "Ada", "role" => "admin"];
print_r(array_values($user));
Output
Array
(
[0] => Ada
[1] => admin
)<?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
| Version | Change |
|---|---|
| PHP 4.0 | Added |
In other languages
dict.values()· PythonObject.values()· JavaScriptarray.values()· JavaScript
Related
array_keys()· Return all the keys of an array, or only the keys whose value matches a search value.array_filter()· Keep only the elements for which a callback returns true. Without a callback it removes empty values; keys are kept.array_is_list()· Check whether an array's keys are 0, 1, 2… in order, so it would encode as a JSON array. Added in PHP 8.1.- PHP Arrays · tutorial
- PHP Array Functions · tutorial