★ wanayoo — archive 1999 http://fr.php.net/manual/ru/function.array-values.phpNouvelle recherche | Portail wanayoo
PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<array_unshiftarray_walk_recursive>
view the version of this page
Last updated: Sun, 20 Mar 2005

array_values

(PHP 4 , PHP 5)

array_values -- Выбрать все значения массива

Описание

array array_values ( array input )

array_values() возвращает индексный массив, содержащий все значения массива input.

Пример 1. Пример использованияarray_values()

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

Выведет:

Array
(
   [0] => XL
   [1] => gold
)

См. также array_keys().



add a note add a note User Contributed Notes
array_values
28-Apr-2004 03:47
<?php
/**
   flatten an arbitrarily deep multidimensional array
   into a list of its scalar values
   (may be inefficient for large structures)
   (will infinite recurse on self-referential structures)
   (could be extended to handle objects)
*/
function array_values_recursive($ary)
{
  
$lst = array();
   foreach(
array_keys($ary) as $k ){
    
$v = $ary[$k];
     if (
is_scalar($v)) {
        
$lst[] = $v;
     } elseif (
is_array($v)) {
        
$lst = array_merge( $lst,
          
array_values_recursive($v)
         );
     }
   }
   return
$lst;
}
?>

code till dawn!  -mark meves!
cyberphant0m AT earthlink DOT net
28-Feb-2004 06:24
That may be true, however I doubt that anyone should have that big of an array. If they do then they probably are doing some intense computing in which case, they may want to opt for the power of C++.
nopy at users dot sourceforge dot net
24-Oct-2003 12:36
Just a warning that re-indexing an array by array_values() may cause you to reach the memory limit unexpectly.

For example, if your PHP momory_limits is 8MB,
 and says there's a BIG array $bigArray which allocate 5MB of memory.

Doing this will cause PHP exceeds the momory limits:

<?php
  $bigArray
= array_values( $bigArray );
?>

It's because array_values() does not re-index $bigArray directly,
it just re-index it into another array, and assign to itself later.
04-Nov-2002 04:48
also useful to use for list(), if the array for input is the result of a function that only returns associative arrays:

list($var1, $var2, $var3) = array_values(myfunc("only returns assoc arrays"));
mailseppel at gmx dot de
04-Oct-2002 01:10
Remember, that the following way of fetching data from a mySql-Table will do exactly the thing as carl described before: An array, which data may be accessed both by numerical and DB-ID-based Indexes:

<?php
$row
= mysql_fetch_array($db_result, $db_link);
?>

Hope I haven't misunderstood anything here.. :)
carl at thep.lu.se
30-Jan-2002 12: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.
richard at phpguru dot org
19-Dec-2001 09: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.

<array_unshiftarray_walk_recursive>
 Last updated: Sun, 20 Mar 2005
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This mirror generously provided by: nexen.net
Last updated: Wed Mar 23 05:13:59 2005 CET