php-doc-en/reference/mongo/mongocursor/sort.xml
Derick Rethans 255568b4c9 Explain the fields array better.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@321508 c90b9560-bf6c-de11-be94-00142212c4b1
2011-12-29 14:51:09 +00:00

101 lines
2.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongocursor.sort" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoCursor::sort</refname>
<refpurpose>Sorts the results by given fields</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type>MongoCursor</type><methodname>MongoCursor::sort</methodname>
<methodparam><type>array</type><parameter>fields</parameter></methodparam>
</methodsynopsis>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term>
<parameter>fields</parameter>
</term>
<listitem>
<para>
An array of fields by which to sort. Each element in the array has as
key the field name, and as value either <literal>1</literal> for
ascending sort, or <literal>-1</literal> for descending sort.
</para>
<para>
Each result is first sorted on the first field in the array, then (if
it exists) on the second field in the array, etc. This means that the
order of the fields in the <parameter>fields</parameter> array is
important. See also the examples section.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the same cursor that this method was called on.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
Throws <classname>MongoCursorException</classname> if this cursor has started iterating.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoCursor::sort</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// Sort on field x, ascending
$cursor->sort(array('x' => 1));
// The order in the associative array is important. For instance, these two
// examples will yield different results:
// Sort on date ascending and age descending
$cursor->sort(array('date' => 1, 'age' => -1));
// Sort on age descending and date ascending
$cursor->sort(array('age' => -1, 'date' => 1));
?>
]]>
</programlisting>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->