- Fix for bug #14104 (added documentation on how to pass object member

functions to usort)


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@62786 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Derick Rethans 2001-11-19 08:56:03 +00:00
parent 4e856cd765
commit 98cf617991

View file

@ -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>
@ -3537,6 +3537,10 @@ while (list ($key, $value) = each ($a)) {
second. If two members compare as equal, their order in the
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>
@ -3622,6 +3626,55 @@ $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>
<para>
<warning>
<para>