Edit report at https://bugs.php.net/bug.php?id=26338&edit=1
ID: 26338 Updated by: ni...@php.net Reported by: Xuefer at 21cn dot com Summary: Add function for fetching column from an array -Status: Open +Status: Closed Type: Feature/Change Request Package: *General Issues Operating System: all PHP Version: 4.3.4 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: array_column has been merged for PHP 5.5. Previous Comments: ------------------------------------------------------------------------ [2013-03-15 14:56:22] ni...@php.net RFC for this feature was accepted, but not yet merged: https://wiki.php.net/rfc/array_column ------------------------------------------------------------------------ [2003-11-24 22:30:34] Xuefer at 21cn dot com 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 ------------------------------------------------------------------------ [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 https://bugs.php.net/bug.php?id=26338&edit=1