mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Clarify array_unique & array_diff comparisation.
FIXME: when exactly were these broken? This should fix some docbugs git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@57557 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
4c78d46018
commit
a3b8d41417
1 changed files with 43 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.92 $ -->
|
||||
<!-- $Revision: 1.93 $ -->
|
||||
<reference id="ref.array">
|
||||
<title>Array Functions</title>
|
||||
<titleabbrev>Arrays</titleabbrev>
|
||||
|
@ -202,6 +202,20 @@ $result = array_diff ($array1, $array2);
|
|||
<literal>array ("blue");</literal>. Multiple occurences in
|
||||
$array1 are all treated the same way.
|
||||
</para>
|
||||
<note>
|
||||
<simpara>
|
||||
Two elements are considered equal if and only if
|
||||
<literal>(string) $elem1 === (string) $elem2</literal>. In words:
|
||||
when the string representation is the same.
|
||||
<!-- TODO: example of it... -->
|
||||
</simpara>
|
||||
</note>
|
||||
<warning>
|
||||
<simpara>
|
||||
This was broken in PHP 4.0.4!
|
||||
<!-- TODO: when exactly was this broken?... -->
|
||||
</simpara>
|
||||
</warning>
|
||||
<para>
|
||||
See also <function>array_intersect</function>.
|
||||
</para>
|
||||
|
@ -1386,6 +1400,23 @@ echo "sum(b) = ".array_sum($b)."\n";
|
|||
keep the first key encountered for every value, and ignore all
|
||||
following keys.
|
||||
</para>
|
||||
<note>
|
||||
<simpara>
|
||||
Two elements are considered equal if and only if
|
||||
<literal>(string) $elem1 === (string) $elem2</literal>. In words:
|
||||
when the string representation is the same.
|
||||
<!-- TODO: example of it... -->
|
||||
</simpara>
|
||||
<simpara>
|
||||
The first element will be used.
|
||||
</simpara>
|
||||
</note>
|
||||
<warning>
|
||||
<simpara>
|
||||
This was broken in PHP 4.0.4!
|
||||
<!-- TODO: when exactly was this broken?... -->
|
||||
</simpara>
|
||||
</warning>
|
||||
<para>
|
||||
<example>
|
||||
<title><function>array_unique</function> example</title>
|
||||
|
@ -1403,27 +1434,22 @@ print_r($result);
|
|||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
Note that <function>array_unique</function> take into account
|
||||
value's type. This is usually of no matter, except when it
|
||||
comes to compare numbers, which can be of several types.
|
||||
This may lead to confusing results.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title><function>array_unique</function> and types</title>
|
||||
<programlisting role="php">
|
||||
$input = array (4,"3",3,"4",4,4);
|
||||
$input = array (4,"4","3",4,3,"3");
|
||||
$result = array_unique ($input);
|
||||
print_r($result);
|
||||
// this will output :
|
||||
//Array
|
||||
//(
|
||||
// [0] => 3
|
||||
// [1] => 3
|
||||
// [2] => 4
|
||||
// [3] => 4
|
||||
//)
|
||||
var_dump($result);
|
||||
|
||||
/* output:
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(4)
|
||||
[1]=>
|
||||
string(1) "3"
|
||||
}
|
||||
*/
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
|
|
Loading…
Reference in a new issue