Use English, transcription of array comparison

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@188991 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Jakub Vrana 2005-06-22 08:20:40 +00:00
parent d9ba2b3289
commit a719c936e7

View file

@ -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 @@ case "a": // never reached because "a" is already matched with 0
</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 @@ case "a": // never reached because "a" is already matched with 0
<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 @@ case "a": // never reached because "a" is already matched with 0
<row>
<entry><type>array</type></entry>
<entry><type>array</type></entry>
<entry>count(op1) &lt; count(op2) =&gt; op1 &lt; op2, key from op1 not found in op2 =&gt; 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>,