<HTML ><HEAD ><TITLE >array_multisort</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual de PHP" HREF="index.html"><LINK REL="UP" TITLE="Funciones de matrices" HREF="ref.array.html"><LINK REL="PREVIOUS" TITLE="array_merge" HREF="function.array-merge.html"><LINK REL="NEXT" TITLE="array_pad" HREF="function.array-pad.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" >Manual de PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.array-merge.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.array-pad.html" ACCESSKEY="N" >Siguiente</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.array-multisort" ></A >array_multisort</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN5190" ></A ><P > (PHP 4 )</P >array_multisort -- Sort multiple or multi-dimensional arrays</DIV ><DIV CLASS="refsect1" ><A NAME="AEN5193" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >array_multisort</B > ( array ar1 [, mixed arg [, mixed ... [, array ...]]])<BR ></BR ><P > <B CLASS="function" >array_multisort()</B > can be used to sort several arrays at once or a multi-dimensional array according by one of more dimensions. It maintains key association when sorting. </P ><P > The input arrays are treated as columns of a table to be sorted by rows - this resembles the functionality of SQL ORDER BY clause. The first array is the primary one to sort by. The rows (values) in that array that compare the same are sorted by the next input array, and so on. </P ><P > The argument structure of this function is a bit unusual, but flexible. The very first argument has to be an array. Subsequently, each argument can be either an array or a sorting flag from the following lists. </P ><P > Sorting order flags: <P ></P ><UL ><LI ><P >SORT_ASC - sort in ascending order</P ></LI ><LI ><P >SORT_DESC - sort in descending order</P ></LI ></UL > </P ><P > Sorting type flags: <P ></P ><UL ><LI ><P >SORT_REGULAR - compare items normally</P ></LI ><LI ><P >SORT_NUMERIC - compare items numerically</P ></LI ><LI ><P >SORT_STRING - compare items as strings</P ></LI ></UL > </P ><P > No two sorting flags of the same type can be specified after each array. The sorting flags specified after an array argument apply only to that array - they are reset to default SORT_ASC and SORT_REGULAR before each new array argument. </P ><P > Devuelve <TT CLASS="constant" ><B >TRUE</B ></TT > si todo fue bien, <TT CLASS="constant" ><B >FALSE</B ></TT > en caso de fallo. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5233" ></A ><P ><B >Ejemplo 1. Sorting multiple arrays</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$ar1 = array ("10", 100, 100, "a"); $ar2 = array (1, 3, "2", 1); array_multisort ($ar1, $ar2);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > In this example, after sorting, the first array will contain 10, "a", 100, 100. The second array will contain 1, 1, "2", 3. The entries in the second array corresponding to the identical entries in the first array (100 and 100) were sorted as well. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN5238" ></A ><P ><B >Ejemplo 2. Sorting multi-dimensional array</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1)); array_multisort ($ar[0], SORT_ASC, SORT_STRING, $ar[1], SORT_NUMERIC, SORT_DESC);</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > In this example, after sorting, the first array will contain 10, 100, 100, "a" (it was sorted as strings in ascending order), and the second one will contain 1, 3, "2", 1 (sorted as numbers, in descending order). </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.array-merge.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Inicio</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.array-pad.html" ACCESSKEY="N" >Siguiente</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >array_merge</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.array.html" ACCESSKEY="U" >Subir</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >array_pad</TD ></TR ></TABLE ></DIV ></BODY ></HTML >