#26338 [Opn]: 2nd param for array_values

From: Date: Tue, 25 Nov 2003 03:30:34 +0000
Subject: #26338 [Opn]: 2nd param for array_values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-50949@lists.php.net to get a copy of this message
ID: 26338 User updated by: Xuefer at 21cn dot com Reported By: Xuefer at 21cn dot com Status: Open Bug Type: Feature/Change Request Operating System: all PHP Version: 4.3.4 New Comment: if anyone think we should not modify array_values i have anohter suggested name: array_column($array, $whichColumn) because it's mostly used to get all fields(foreah row) in one column Previous Comments: ------------------------------------------------------------------------ [2003-11-20 22:51:27] Xuefer at 21cn dot com Description: ------------ old: Usage: array array_values ( array input ) Purpose: Return all the values of an array new suggestion: Usage: array array_values ( array input, [mixed key] ) Purpose: Return all the values of an array key default to null, which is same as old array_values if key is_int or is_string it act like this: function array_values($input, $key) { $ret = array(); foreach ($input as $value) { $ret[] = $value[$key]; } return $ret; } this is very useful to collect ids e.g.: $idrows = db_query_all_rows("select id from table1"); $ids = implode(',', array_values($idrows, 'id')); $myrows = db_query_all_rows("select .... from table2 where id IN($ids)"); (db_query_all_rows is custom function which fetch all rows of query result) thanks ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26338&edit=1

« previous php.bugs (#50949) next »