From a719c936e7959b99698fd711252ef1c72ffa848e Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Wed, 22 Jun 2005 08:20:40 +0000 Subject: [PATCH] Use English, transcription of array comparison git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@188991 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/operators.xml | 47 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/language/operators.xml b/language/operators.xml index 8e8d901d86..6c50c652ac 100644 --- a/language/operators.xml +++ b/language/operators.xml @@ -1,5 +1,5 @@ - + Operators @@ -549,6 +549,10 @@ case "a": // never reached because "a" is already matched with 0 + + If types of operands differ, comparison is done according to the following + table (in order). + Comparison with Different Types @@ -573,7 +577,8 @@ case "a": // never reached because "a" is already matched with 0 object object - Built-in classes can define its own comparison, different classes are uncomparable, same class - compare properties the same way as arrays + Built-in classes can define its own comparison, different classes + are uncomparable, same class - compare properties the same way as arrays string, resource or number @@ -583,21 +588,53 @@ case "a": // never reached because "a" is already matched with 0 array array - count(op1) < count(op2) => op1 < op2, key from op1 not found in op2 => uncomparable, otherwise - compare value by value + 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) array anything - array is greater + array is always greater object anything - object is greater + object is always greater
+ + + Transcription of standard array comparison + + 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 +} +?> +]]> + + + See also strcasecmp,