PHP array_values() Function

6 Jan 2025 | 1 min read

The array_values( ) function is an inbuilt function of PHP. It is used to get an array of values from another array that may contain key-value pairs. This function was introduced in PHP 4.0.

Syntax

Parameters

ParameterDescriptionIs compulsory
arraySpecifying an array.compulsory

Return Values

The array_values( ) function returns an array containing all the values of an array.

Important note:

The returned array will have numeric keys, starting at 0 and increase by 1.

Example 1

Output:

 Array ( [0] =>javatpoint [1] =>udemy [2] =>byjus ) 

Example 2

Output:

 Array ( [0] => apple [1] => ball [2] => cat ) 

Example 3

Output:

 Array ( [0] =>mario [1] => need for speed [2] =>igi [3] => road race ) 

Example 4

Output:

 Array ( [0] =>Narendramodi [1] => 67 [2] => INDIA )