From 909c25dafa89874ea5c50a402c6cf2947ff8f8ed Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Thu, 9 Oct 2003 07:28:40 +0000 Subject: [PATCH] Documentation for new functions in PHP5 git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@142099 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../array/functions/array-diff-uassoc.xml | 110 ++++++++++++++ .../array/functions/array-udiff-assoc.xml | 130 ++++++++++++++++ .../array/functions/array-udiff-uassoc.xml | 139 ++++++++++++++++++ reference/array/functions/array-udiff.xml | 121 +++++++++++++++ 4 files changed, 500 insertions(+) create mode 100644 reference/array/functions/array-diff-uassoc.xml create mode 100644 reference/array/functions/array-udiff-assoc.xml create mode 100644 reference/array/functions/array-udiff-uassoc.xml create mode 100644 reference/array/functions/array-udiff.xml diff --git a/reference/array/functions/array-diff-uassoc.xml b/reference/array/functions/array-diff-uassoc.xml new file mode 100644 index 0000000000..9a7998faec --- /dev/null +++ b/reference/array/functions/array-diff-uassoc.xml @@ -0,0 +1,110 @@ + + + + + + array_diff_uassoc + Computes the difference of arrays with additional index check which is performed by a user supplied callback function. + + + Description + + arrayarray_diff_assoc + arrayarray1 + arrayarray2 + array ... + callbackkey_compare_func + + + array_diff_uassoc returns an array + containing all the values from array1 + that are not present in any of the other arguments. + Note that the keys are used in the comparison unlike + array_diff. This comparison is done by a user supplied callback function. + It must return an integer less than, equal + to, or greater than zero if the first argument is considered to + be respectively less than, equal to, or greater than the + second. This is unlike array_diff_assoc where an + internal function for comparing the indices is used. + + + + <function>array_diff_uassoc</function> example + + $b)? 1:-1; +} + +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$result = array_diff_uassoc($array1, $array2, "key_compare_func"); + +/* The result is: +Array +( + [b] => brown + [c] => blue + [0] => red +) +*/ +?> +]]> + + + + + In our example above you see the "a" => "green" + pair is present in both arrays and thus it is not in the ouput from the + function. Unlike this, the pair 0 => "red" + is in the ouput because in the second argument "red" + has key which is 1. + + + The equality of 2 indices is checked by the user supplied callback function. + + + + Please note that this function only checks one dimension of a n-dimensional + array. Of course you can check deeper dimensions by using, for example, + array_diff_uassoc($array1[0], $array2[0], "key_compare_func");. + + + + See also + array_diff, + array_diff_assoc, + array_udiff, + array_udiff_assoc, + array_udiff_uassoc, + array_intersect, + array_intersect_assoc, + array_uintersect, + array_uintersect_assoc and + array_uintersect_uassoc. + + + + + diff --git a/reference/array/functions/array-udiff-assoc.xml b/reference/array/functions/array-udiff-assoc.xml new file mode 100644 index 0000000000..eb9bda95e1 --- /dev/null +++ b/reference/array/functions/array-udiff-assoc.xml @@ -0,0 +1,130 @@ + + + + + + array_udiff_assoc + Computes the difference of arrays with additional index check. The data is compared by using a callback function. + + + Description + + arrayarray_udiff_assoc + arrayarray1 + arrayarray2 + array ... + callbackdata_compare_func + + + array_udiff_assoc returns an array + containing all the values from array1 + that are not present in any of the other arguments. + Note that the keys are used in the comparison unlike + array_diff and array_udiff. + The comparison of arrays' data is performed by using an user-supplied + callback. In this aspect the behaviour is opposite to the behaviour of + array_diff_assoc which uses internal function for + comparison. + + + + <function>array_udiff_assoc</function> example + +priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member)? 1:-1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr( 3), 1=> new cr(4), 2 => new cr(-15),); + +$result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr")); +print_r($result); +?> + +/* The result is: +Array +( + [0.1] => cr Object + ( + [priv_member:private] => 9 + ) + + [0.5] => cr Object + ( + [priv_member:private] => 12 + ) + + [0] => cr Object + ( + [priv_member:private] => 23 + ) +) +*/ +?> +]]> + + + + + In our example above you see the "1" => new cr(4) + pair is present in both arrays and thus it is not in the ouput from the + function. + + + For comparison is used the user supplied callback function. + It must return an integer less than, equal + to, or greater than zero if the first argument is considered to + be respectively less than, equal to, or greater than the + second. + + + + Please note that this function only checks one dimension of a n-dimensional + array. Of course you can check deeper dimensions by using, for example, + array_udiff_assoc($array1[0], $array2[0], "some_comparison_func");. + + + + See also + array_diff, + array_diff_assoc, + array_diff_uassoc, + array_udiff, + array_udiff_uassoc, + array_intersect, + array_intersect_assoc, + array_uintersect, + array_uintersect_assoc and + array_uintersect_uassoc. + + + + + diff --git a/reference/array/functions/array-udiff-uassoc.xml b/reference/array/functions/array-udiff-uassoc.xml new file mode 100644 index 0000000000..44f351c6b1 --- /dev/null +++ b/reference/array/functions/array-udiff-uassoc.xml @@ -0,0 +1,139 @@ + + + + + + array_udiff_uassoc + Computes the difference of arrays with additional index check. The data is compared by using a callback function. The index check is done by a callback function also + + + Description + + arrayarray_udiff_uassoc + arrayarray1 + arrayarray2 + array ... + callbackdata_compare_func + callbackkey_compare_func + + + array_udiff_uassoc returns an array + containing all the values from array1 + that are not present in any of the other arguments. + Note that the keys are used in the comparison unlike + array_diff and array_udiff. + The comparison of arrays' data is performed by using an user-supplied + callback : data_compare_func. In this aspect + the behaviour is opposite to the behaviour of + array_diff_assoc which uses internal function for + comparison. The comparison of keys (indices) is done also by the + callback function key_compare_func. This + behaviour is unlike what array_udiff_assoc does, since + the latter compares the indices by using an internal function. + + + + <function>array_udiff_uassoc</function> example + +priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member)? 1:-1; + } + static function comp_func_key($a, $b) { + if ($a === $b) return 0; + return ($a > $b)? 1:-1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr( 3), 1=> new cr(4), 2 => new cr(-15),); + +$result = array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr","comp_func_key")); +print_r($result); +?> + +/* The result is: +Array +( + [0.1] => cr Object + ( + [priv_member:private] => 9 + ) + + [0.5] => cr Object + ( + [priv_member:private] => 12 + ) + + [0] => cr Object + ( + [priv_member:private] => 23 + ) +) +*/ +?> +]]> + + + + + In our example above you see the "1" => new cr(4) + pair is present in both arrays and thus it is not in the ouput from the + function. Keep in mind that you have to supply 2 callback functions. + + + For comparison is used the user supplied callback function. + It must return an integer less than, equal + to, or greater than zero if the first argument is considered to + be respectively less than, equal to, or greater than the + second. + + + + Please note that this function only checks one dimension of a n-dimensional + array. Of course you can check deeper dimensions by using, for example, + array_udiff_assoc($array1[0], $array2[0], "some_comparison_func");. + + + + See also + array_diff, + array_diff_assoc, + array_diff_uassoc, + array_udiff, + array_udiff_assoc, + array_intersect, + array_intersect_assoc, + array_uintersect, + array_uintersect_assoc and + array_uintersect_uassoc. + + + + + diff --git a/reference/array/functions/array-udiff.xml b/reference/array/functions/array-udiff.xml new file mode 100644 index 0000000000..ee736f3fd6 --- /dev/null +++ b/reference/array/functions/array-udiff.xml @@ -0,0 +1,121 @@ + + + + + + array_udiff + Computes the difference of arrays by using callback function for data comparison. + + + Description + + arrayarray_udiff + arrayarray1 + arrayarray2 + array ... + callbackdata_compare_func + + + array_udiff returns an array + containing all the values of array1 + that are not present in any of the other arguments. + Note that keys are preserved. For the comparison of the data + data_compare_function is used. + It must return an integer less than, equal + to, or greater than zero if the first argument is considered to + be respectively less than, equal to, or greater than the + second. This is unlike array_diff which uses an + internal function for comparing the data. + + + + <function>array_udiff</function> example + +priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member)? 1:-1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr( 3), 1=> new cr(4), 2 => new cr(-15),); + +$result = array_udiff($a, $b, array("cr", "comp_func_cr")); +print_r($result); + +/* The result is: +Array +( + [0.5] => cr Object + ( + [priv_member:private] => 12 + ) + + [0] => cr Object + ( + [priv_member:private] => 23 + ) + +) +*/ +?> +]]> + + + + + + Two elements are considered equal if and only if + (string) $elem1 === (string) $elem2. In words: + when the string representation is the same. + + + + + Please note that this function only checks one dimension of a n-dimensional + array. Of course you can check deeper dimensions by using + array_udiff($array1[0], $array2[0], "data_compare_func");. + + + + See also + array_diff, + array_diff_assoc, + array_diff_uassoc, + array_udiff_assoc, + array_udiff_uassoc, + array_intersect, + array_intersect_assoc, + array_uintersect, + array_uintersect_assoc and + array_uintersect_uassoc. + + + + +