mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
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:
parent
d9ba2b3289
commit
a719c936e7
1 changed files with 42 additions and 5 deletions
|
@ -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) < 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>,
|
||||
|
|
Loading…
Reference in a new issue