derick          Mon Nov 19 03:56:03 2001 EDT

  Modified files:              
    /phpdoc/en/functions        array.xml 
  Log:
  - Fix for bug #14104 (added documentation on how to pass object member
    functions to usort)
  
  
Index: phpdoc/en/functions/array.xml
diff -u phpdoc/en/functions/array.xml:1.124 phpdoc/en/functions/array.xml:1.125
--- phpdoc/en/functions/array.xml:1.124 Sun Nov 18 18:45:19 2001
+++ phpdoc/en/functions/array.xml       Mon Nov 19 03:56:03 2001
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.124 $ -->
+<!-- $Revision: 1.125 $ -->
  <reference id="ref.array">
   <title>Array Functions</title>
   <titleabbrev>Arrays</titleabbrev>
@@ -3538,6 +3538,10 @@
      sorted array is undefined.
     </para>
     <para>
+     It is also possible to use a member function of an object as the
+     comparison function. See example number 3 below.
+    </para>
+    <para>
      <example>
       <title><function>usort</function> example</title>
       <programlisting role="php">
@@ -3619,6 +3623,55 @@
 $fruits[1]: grapes
 $fruits[2]: lemons
 ]]>
+      </programlisting>
+     </informalexample>
+    </para>
+
+    <para>
+     <example>
+      <title>
+       <function>usort</function> example using a member function of an object
+      </title>
+      <programlisting role="php">
+class TestObj {
+    var $name;
+
+    function TestObj($name)
+    {
+        $this->name = $name;
+    }
+
+    /* This is the static comparing function: */
+    function cmp_obj($a, $b)
+    {
+        $al = strtolower($a->name);
+        $bl = strtolower($b->name);
+        if ($al == $bl) return 0;
+        return ($al > $bl) ? +1 : -1;
+    }
+}
+
+$a[] = new TestObj("c");
+$a[] = new TestObj("b");
+$a[] = new TestObj("d");
+
+uasort($a, array ("TestObj", "cmp_obj"));
+
+foreach ($a as $item) {
+    print $item->name."\n";
+}
+      </programlisting>
+     </example>
+    </para>
+    <para>
+     This example would display:
+    </para>
+    <para>
+     <informalexample>
+      <programlisting>
+b
+c
+d
       </programlisting>
      </informalexample>
     </para>


Reply via email to