Array Functions

PHP array_values() Function

Topic: PHP Array ReferencePrev|Next

Description

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

The returned array will be indexed numerically, starting with 0 and increase each time by 1.

The following table summarizes the technical details of this function.

Return Value: Returns an indexed array of all the values of an array.
Version: PHP 4+

Syntax

The basic syntax of the array_values() function is given with:

array_values(array);

The following example shows the array_values() function in action.

<?php
// Sample array
$alphabets = array("a"=>"apple", "b"=>"ball", "c"=>"cat", "d"=>"dog");

// Getting all the values from alphabets array
$result = array_values($alphabets);
print_r($result);
?>

Parameters

The array_values() function accepts the following parameters.

Parameter Description
array Required. Specifies the array to work on.

More Examples

Here're some more examples showing how array_values() function actually works:

This function may ignore the numeric indexes, let's try out an example and see how it works:

<?php
// Sample array
$numbers = array(4=>10, 3=>25, 1=>50, 2=>75);

// Adding a value to the numbers array at index 0
$numbers[0] = 100;

// Getting all the values from numbers array
$result = array_values($numbers);
print_r($result);
?>
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties