vrana Wed Jun 22 04:20:41 2005 EDT
Modified files:
/phpdoc/en/language operators.xml
Log:
Use English, transcription of array comparison
http://cvs.php.net/diff.php/phpdoc/en/language/operators.xml?r1=1.88&r2=1.89&ty=u
Index: phpdoc/en/language/operators.xml
diff -u phpdoc/en/language/operators.xml:1.88
phpdoc/en/language/operators.xml:1.89
--- phpdoc/en/language/operators.xml:1.88 Tue Jun 21 20:07:28 2005
+++ phpdoc/en/language/operators.xml Wed Jun 22 04:20:40 2005
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.88 $ -->
+<!-- $Revision: 1.89 $ -->
<chapter id="language.operators">
<title>Operators</title>
<simpara>
@@ -549,6 +549,10 @@
</informalexample>
</para>
+ <para>
+ If types of operands differ, comparison is done according to the following
+ table (in order).
+ </para>
<table>
<title>Comparison with Different Types</title>
<tgroup cols="3">
@@ -573,7 +577,8 @@
<row>
<entry><type>object</type></entry>
<entry><type>object</type></entry>
- <entry>Built-in classes can define its own comparison, different
classes are uncomparable, same class - compare properties the same way as
arrays</entry>
+ <entry>Built-in classes can define its own comparison, different classes
+ are uncomparable, same class - compare properties the same way as
arrays</entry>
</row>
<row>
<entry><type>string</type>, <type>resource</type> or
<type>number</type></entry>
@@ -583,21 +588,53 @@
<row>
<entry><type>array</type></entry>
<entry><type>array</type></entry>
- <entry>count(op1) < count(op2) => op1 < op2, key from op1 not
found in op2 => uncomparable, otherwise - compare value by value</entry>
+ <entry>Array with fewer members is smaller, if key from operand 1 is not
+ found in operand 2 then arrays are uncomparable, otherwise - compare
+ value by value (see following example)</entry>
</row>
<row>
<entry><type>array</type></entry>
<entry>anything</entry>
- <entry><type>array</type> is greater</entry>
+ <entry><type>array</type> is always greater</entry>
</row>
<row>
<entry><type>object</type></entry>
<entry>anything</entry>
- <entry><type>object</type> is greater</entry>
+ <entry><type>object</type> is always greater</entry>
</row>
</tbody>
</tgroup>
</table>
+ <para>
+ <example>
+ <title>Transcription of standard array comparison</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+// Arrays are compared like this with standard comparison operators
+function standard_array_compare($op1, $op2)
+{
+ if (count($op1) < count($op2)) {
+ return -1; // $op1 < $op2
+ } elseif (count($op1) > count($op2)) {
+ return 1; // $op1 > $op2
+ }
+ foreach ($op1 as $key => $val) {
+ if (!array_key_exists($key, $op2)) {
+ return null; // uncomparable
+ } elseif ($val < $op2[$key]) {
+ return -1;
+ } elseif ($val > $op2[$key]) {
+ return 1;
+ }
+ }
+ return 0; // $op1 == $op2
+}
+?>
+]]>
+ </programlisting>
+ </example>
+ </para>
<para>
See also <function>strcasecmp</function>,