Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

dbx_compare(3) [php man page]

DBX_COMPARE(3)								 1							    DBX_COMPARE(3)

dbx_compare - Compare two rows for sorting purposes

SYNOPSIS
int dbx_compare (array $row_a, array $row_b, string $column_key, [int $flags = DBX_CMP_ASC | DBX_CMP_NATIVE]) DESCRIPTION
dbx_compare(3) is a helper function for dbx_sort(3) to ease the make and use of the custom sorting function. PARAMETERS
o $row_a - First row o $row_b - Second row o $column_key - The compared column o $flags - The $flags can be set to specify comparison direction: o DBX_CMP_ASC - ascending order o DBX_CMP_DESC - descending order and the preferred comparison type: o DBX_CMP_NATIVE - no type conversion o DBX_CMP_TEXT - compare items as strings o DBX_CMP_NUMBER - compare items numerically One of the direction and one of the type constant can be combined with bitwise OR operator (|). RETURN VALUES
Returns 0 if the row_a[$column_key] is equal to row_b[$column_key], and 1 or -1 if the former is greater or is smaller than the latter one, respectively, or vice versa if the $flag is set to DBX_CMP_DESC. EXAMPLES
Example #1 dbx_compare(3) example <?php function user_re_order($a, $b) { $rv = dbx_compare($a, $b, "parentid", DBX_CMP_DESC); if (!$rv) { $rv = dbx_compare($a, $b, "id", DBX_CMP_NUMBER); } return $rv; } $link = dbx_connect(DBX_ODBC, "", "db", "username", "password") or die("Could not connect"); $result = dbx_query($link, "SELECT id, parentid, description FROM table ORDER BY id"); // data in $result is now ordered by id dbx_sort($result, "user_re_order"); // date in $result is now ordered by parentid (descending), then by id dbx_close($link); ?> SEE ALSO
dbx_sort(3). PHP Documentation Group DBX_COMPARE(3)

Check Out this Related Man Page

ARRAY_COLUMN(3) 							 1							   ARRAY_COLUMN(3)

array_column - Return the values from a single column in the input array

SYNOPSIS
array array_column (array $array, mixed $column_key, [mixed $index_key = null]) DESCRIPTION
array_column(3) returns the values from a single column of the $array, identified by the $column_key. Optionally, you may provide an $index_key to index the values in the returned array by the values from the $index_key column in the input array. PARAMETERS
o $array - A multi-dimensional array (record set) from which to pull a column of values. o $column_key - The column of values to return. This value may be the integer key of the column you wish to retrieve, or it may be the string key name for an associative array. It may also be NULL to return complete arrays (useful together with $index_key to reindex the array). o $index_key - The column to use as the index/keys for the returned array. This value may be the integer key of the column, or it may be the string key name. RETURN VALUES
Returns an array of values representing a single column from the input array. EXAMPLES
Example #1 Get column of first names from recordset <?php // Array representing a possible record set returned from a database $records = array( array( 'id' => 2135, 'first_name' => 'John', 'last_name' => 'Doe', ), array( 'id' => 3245, 'first_name' => 'Sally', 'last_name' => 'Smith', ), array( 'id' => 5342, 'first_name' => 'Jane', 'last_name' => 'Jones', ), array( 'id' => 5623, 'first_name' => 'Peter', 'last_name' => 'Doe', ) ); $first_names = array_column($records, 'first_name'); print_r($first_names); ?> The above example will output: Array ( [0] => John [1] => Sally [2] => Jane [3] => Peter ) Example #2 Get column of last names from recordset, indexed by the "id" column <?php // Using the $records array from Example #1 $last_names = array_column($records, 'last_name', 'id'); print_r($last_names); ?> The above example will output: Array ( [2135] => Doe [3245] => Smith [5342] => Jones [5623] => Doe ) PHP Documentation Group ARRAY_COLUMN(3)
Man Page