home HOME

PHP Basic
PHP HOME
PHP Intro
PHP Install
PHP Syntax
PHP Variables
PHP String
PHP Operators
PHP If...Else
PHP Switch
PHP Arrays
PHP Looping
PHP Functions
PHP Forms
PHP $_GET
PHP $_POST

PHP Advanced
PHP Date
PHP Include
PHP File
PHP File Upload
PHP Cookies
PHP Sessions
PHP E-mail
PHP Secure E-mail
PHP Error
PHP Exception
PHP Filter

PHP Database
MySQL Introduction
MySQL Connect
MySQL Create
MySQL Insert
MySQL Select
MySQL Where
MySQL Order By
MySQL Update
MySQL Delete
PHP ODBC

PHP XML
XML Expat Parser
XML DOM
XML SimpleXML

PHP and AJAX
AJAX Introduction
XMLHttpRequest
AJAX Suggest
AJAX XML
AJAX Database
AJAX responseXML
AJAX Live Search
AJAX RSS Reader
AJAX Poll

PHP Reference
PHP Array
PHP Calendar
PHP Date
PHP Directory
PHP Error
PHP Filesystem
PHP Filter
PHP FTP
PHP HTTP
PHP Libxml
PHP Mail
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip

PHP Quiz
PHP Quiz

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Forum

Helping W3Schools

pixels

PHP usort() Function


PHP Array Reference Complete PHP Array Reference

Definition and Usage

The usort() function sorts an array by a user defined comparison function.

This function assigns new keys for the elements in the array. Existing keys will be removed.

This function returns TRUE on success, or FALSE on failure.

This function is useful for sorting with custom algorithms.

Syntax

usort(array,sorttype)

Parameter Description
array Required. Specifies the array to sort
function Required. A user specified function.

The function must return -1, 0, or 1 for this method to work correctly. It should be written to accept two parameters to compare, and it should work something like this:

  • If a = b, return 0
  • If a > b, return 1
  • If a < b, return -1


Example

<?php
function my_sort($a, $b)
  {
  if ($a == $b) return 0;
  return ($a > $b) ? -1 : 1;
  }

$arr = array("Peter", "glenn","Cleveland",
"peter","cleveland", "Glenn");
usort($arr, "my_sort");

print_r ($arr);
?>

The output of the code above will be:

Array
(
[0] => peter
[1] => glenn
[2] => cleveland
[3] => Peter
[4] => Glenn
[5] => Cleveland
) 


PHP Array Reference Complete PHP Array Reference


What do you want your Web site to do?

Ektron



Ektron’s new Extranet for Client Collaboration is designed to manage documents and timelines while facilitating collaboration among your internal and external project stake holders.
Ektron
Features include:

Client authentication using Ektron's robust membership module, allowing you to add, manage and notify your project stake holders
Project Status Dashboard allowing for visual navigation across all aspects of your project, efficiently and effectively from one single location
Wiki Scribble Pad for tracking major additions, changes or other related announcements for your project teams
Discussion forums and message boards to facilitate conversations within a non real-time environment
Integrated Document Management allowing you to maintain a complete history and audit trail of all documents that can affect the success of your project
Milestone Tracking with Outlook synchronization ensuring all your goals and deadlines are met
Public and Private Blogs for further extending communication across the team regarding status, feature creep or other external changes

See why there are 20,000+ Ektron integrations worldwide.

Click here to learn more, then request a live online demo or download a FREE TRIAL




diploma   

Get Your Diploma!

W3Schools' Online Certification Program is the perfect solution for busy professionals who need to balance work, family, and career building.

The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.

The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.


Jump to: Top of Page or HOME or Printer Friendly Printer friendly page

W3Schools provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2007 by Refsnes Data. All Rights Reserved.

Validate Validate W3C-WAI level A conformance icon W3Schools was converted to XHTML in December 1999
SITE SEARCH
 
About W3Schools
W3Schools Forum
IISProtect
Password Protect
Your Web Pages
WEB HOSTING
$15 Domain Name
Registration
Save $20 / year!
UK Domain Names
UK Web Hosting

Alojamiento Web
Buy UK Domain Names
Register Domain Names
Cheap Domain Names
Cheap Web Hosting
Best Web Hosting
Domain Name Registration
PHP MySQL Hosting
Top 10 Web Hosting
Web Hosting Providers
Web Hosting Company
WEB BUILDING
Convert HTML to XML
Website Templates
Flash Templates
Website Builder
Internet Business Opportunity
Custom Programming
Web Design Forum
Programming Forum
FREE Trial or Demo
Web Content Manager
Forms,Web Alerts,RSS
Free Thumbnail Maker
Free Video Tutorials
HTML Exam
SHOPPING
UK Wholesalers
UK Wholesale
Online Casinos
Batteries
ONLINE DEGREE
Advance Your Career
with Drexel University
Bachelor's & Master's
Tech Degrees ONLINE
US Web Design Schools
YELLOW PAGES
www.nettkatalogen.no
www.gulex.dk
www.gulex.se
www.gelbex.de

pixels