<HTML ><HEAD ><TITLE >sort</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="Array functions" HREF="ref.array.html"><LINK REL="PREVIOUS" TITLE="sizeof" HREF="function.sizeof.html"><LINK REL="NEXT" TITLE="uasort" HREF="function.uasort.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><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.sizeof.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.uasort.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.sort" >sort</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN4424" ></A >sort -- Sort an array</DIV ><DIV CLASS="refsect1" ><A NAME="AEN4427" ></A ><H2 >Description</H2 ><DIV CLASS="funcsynopsis" ><P ></P ><CODE CLASS="FUNCDEF" >void sort</CODE >(array array);<P ></P ></DIV ><P > This function sorts an array. Elements will be arranged from lowest to highest when this function has completed. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 1. <B CLASS="function" >sort()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 $fruits = array ("lemon", "orange", "banana", "apple"); 3 sort ($fruits); 4 for (reset ($fruits); $key = key ($fruits); next ($fruits)) { 5 echo "fruits[$key] = ".$fruits[$key]."\n"; 6 } 7 </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > This example would display: <TT CLASS="computeroutput" > fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] = orange </TT > The fruits have been sorted in alphabetical order. </P ><P > See also: <A HREF="function.arsort.html" ><B CLASS="function" >arsort()</B ></A >, <A HREF="function.asort.html" ><B CLASS="function" >asort()</B ></A >, <A HREF="function.ksort.html" ><B CLASS="function" >ksort()</B ></A >, <A HREF="function.rsort.html" ><B CLASS="function" >rsort()</B ></A >, and <A HREF="function.usort.html" ><B CLASS="function" >usort()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.sizeof.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.uasort.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >sizeof</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.array.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >uasort</TD ></TR ></TABLE ></DIV ></BODY ></HTML >