★ wanayoo — archive 1999 http://fr.php.net/manual/en/function.array-values.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previousarray_unshiftarray_walknext
Last updated: Thu, 15 Aug 2002
view the printer friendly version or the printer friendly version with notes or change language to Brazilian Portuguese | Chinese | Czech | Dutch | Finnish | French | German | Hungarian | Italian | Japanese | Korean | Polish | Romanian | Russian | Spanish | Turkish

array_values

(PHP 4 )

array_values -- Return all the values of an array

Description

array array_values ( array input)

array_values() returns all the values from the input array.

Example 1. array_values() example

$array = array ("size" => "XL", "color" => "gold");
print_r(array_values ($array));

This will output:
Array
(
    [0] => XL
    [1] => gold
)

Note: This function was added to PHP 4, below is an implementation for those still using PHP 3.

Example 2. Implementation of array_values() for PHP 3 users

function array_values ($arr) {
    $t = array();
    while (list($k, $v) = each ($arr)) {
        $t[] = $v;
    }
    return $t;
}

See also array_keys().

User Contributed Notes
array_values
add a note about notes
richard@phpguru.org
19-Dec-2001 06:56

If you have a numerically indexed array with some keys missing, ie 1, 2, 4, 5 and you want to reindex it so it's 1,2,3,4 *without changing the positions of the values* (ie sort()) then you can use this function to do it.
carl at thep.lu.se
29-Jan-2002 09:59

Indeed you can, and that's what's so great about it. I have, for instance, a function that returns the results of a database query as an array. I want to keep the order that the entries were returned in, but at the same time I want to be able to access them _either_ by the position _or_ by some other index (such as some sort of ID in the database, gotten from elsewhere). In this case, I can make the function return an array from id to [array of values], and by a simple call to array_values() this is transformed into an array indexed from 0 to count()-1. Useful.
add a note about notes
previousarray_unshiftarray_walknext
Last updated: Thu, 15 Aug 2002
show source | credits | stats | mirror sites
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Sun Aug 18 04:45:58 2002 CEST