Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Sort an Array by Values
How To Sort an Array by Values? - PHP Script Tips - PHP Built-in Functions for Arrays
✍: FYIcenter.com
Sorting an array by values is doable by using the sort() function. It will re-order all pairs of keys and values based on the alphanumeric order of the values. Then it will replace all keys with integer keys sequentially starting with 0. So using sort() on arrays with integer keys (traditional index based array) is safe. It is un-safe to use sort() on arrays with string keys (maps). Be careful. Here is a PHP script on how to use sort():
<?php $mixed = array(); $mixed["Zero"] = "PHP"; $mixed[1] = "Perl"; $mixed["Two"] = "Java"; $mixed["3"] = "C+"; $mixed[""] = "Basic"; $mixed[] = "Pascal"; $mixed[] = "FORTRAN"; sort($mixed); print("Sorted by values:\n"); print_r($mixed); ?>
This script will print:
Sorted by values: Array ( [0] => Basic [1] => C+ [2] => FORTRAN [3] => Java [4] => PHP [5] => Pascal [6] => Perl )
2007-04-21, 5406👍, 0💬
Popular Posts:
How To Merge Cells in a Column? - XHTML 1.0 Tutorials - Understanding Tables and Table Cells If you ...
What's the difference between J2SDK 1.5 and J2SDK 5.0? There is no difference, Sun Microsystems just...
How Do I Run JUnit Tests from Command Window? To run JUnit tests from a command window, you need to ...
What is the output of printf("%d")? 1. When we write printf("%d",x); this means compiler will print ...
What is a measure in OLAP ? Measures are the key performance indicator that you want to evaluate. To...