<HTML ><HEAD ><TITLE >uksort</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Array Functions" HREF="ref.array.html"><LINK REL="PREVIOUS" TITLE="uasort" HREF="function.uasort.html"><LINK REL="NEXT" TITLE="usort" HREF="function.usort.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.uasort.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.usort.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.uksort" ></A >uksort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN9304" ></A ><P > (PHP 3>= 3.0.4, PHP 4 )</P >uksort -- Sort an array by keys using a user-defined comparison function </DIV ><DIV CLASS="refsect1" ><A NAME="AEN9307" ></A ><H2 >Description</H2 >void <B CLASS="methodname" >uksort</B > ( array array, callback cmp_function)<BR ></BR ><P > This function will sort the keys of an array using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN9319" ></A ><P ><B >Example 1. <B CLASS="function" >uksort()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >function cmp ($a, $b) { if ($a == $b) return 0; return ($a > $b) ? -1 : 1; } $a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten"); uksort ($a, "cmp"); while (list ($key, $value) = each ($a)) { echo "$key: $value\n"; }</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > This example would display: </P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >20: twenty 10: ten 4: four 3: three</PRE ></TD ></TR ></TABLE > </P ><P > See also <A HREF="function.usort.html" ><B CLASS="function" >usort()</B ></A >, <A HREF="function.uasort.html" ><B CLASS="function" >uasort()</B ></A >, <A HREF="function.sort.html" ><B CLASS="function" >sort()</B ></A >, <A HREF="function.asort.html" ><B CLASS="function" >asort()</B ></A >, <A HREF="function.arsort.html" ><B CLASS="function" >arsort()</B ></A >, <A HREF="function.ksort.html" ><B CLASS="function" >ksort()</B ></A >, <A HREF="function.natsort.html" ><B CLASS="function" >natsort()</B ></A >, and <A HREF="function.rsort.html" ><B CLASS="function" >rsort()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.uasort.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.usort.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >uasort</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.array.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >usort</TD ></TR ></TABLE ></DIV ></BODY ></HTML >