PHP: array_values() function
PHP: Return all the values of an array
The array_values() function is used to fetch all the values from an array. The function indexes the array numerically.
Version:
(PHP 4 and above)
Syntax:
array_values(array1)
Parameter:
Name | Description | Required / Optional |
Type |
---|---|---|---|
array1 | Specifies the name of the array. | Required | Array |
Return value:
Numerically indexed array of values of array1.
Value Type: Array
Example:
<?php
$fruits_list = array('Orange', 'Apple','Banana', 'Cherry');
print_r(array_values($fruits_list));
?>
Output:
Array ( [0] => Orange [1] => Apple [2] => Banana [3] => Cherry )
Pictorial Presentation:

View the example in the browser
Practice here online :
See also
Previous: array_unshift
Next: array_walk_ recursive
PHP: Tips of the Day
Filters the collection using the given callback
Example:
<?php function tips_reject($items, $func) { return array_values(array_diff($items, array_filter($items, $func))); } print_r(tips_reject(['Apple', 'Pear', 'Kiwi', 'Banana'], function ($item) { return strlen($item) > 4; })); ?>
Output:
Array ( [0] => Pear [1] => Kiwi )
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises