better group examples

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@301082 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kristina Chodorow 2010-07-08 14:17:34 +00:00
parent f5b736e852
commit 3b8aa620b5

View file

@ -14,7 +14,7 @@
<methodparam><type>mixed</type><parameter>keys</parameter></methodparam>
<methodparam><type>array</type><parameter>initial</parameter></methodparam>
<methodparam><type>MongoCode</type><parameter>reduce</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>condition</parameter><initializer>array()</initializer></methodparam>
<methodparam choice="opt"><type>array</type><parameter>options</parameter><initializer>array()</initializer></methodparam>
</methodsynopsis>
</refsect1>
@ -103,6 +103,48 @@
&reftitle.examples;
<example>
<title><function>MongoCollection::group</function> example</title>
<para>
This groups documents by category and creates a list of names within that
category.
</para>
<programlisting role="php">
<![CDATA[
<?php
$collection->insert(array("category" => "fruit", "name" => "apple"));
$collection->insert(array("category" => "fruit", "name" => "peach"));
$collection->insert(array("category" => "fruit", "name" => "banana"));
$collection->insert(array("category" => "veggie", "name" => "corn"));
$collection->insert(array("category" => "veggie", "name" => "broccoli"));
$keys = array("category" => 1);
$initial = array("items" => array());
$reduce = "function (obj, prev) { prev.items.push(obj.name); }";
$g = $collection->group($keys, $initial, $reduce);
echo json_encode($g['retval']);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
[{"category":"fruit","items":["apple","peach","banana"]},{"category":"veggie","items":["corn","broccoli"]}]
]]>
</screen>
</example>
<example>
<title><function>MongoCollection::group</function> example</title>
<para>
This example doesn't use any key, so every document will be its own group.
It also uses a condition: only documents that match this condition will be
processed by the grouping function.
</para>
<programlisting role="php">
<![CDATA[
<?php