Added note about array_unique making case of value's types.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@51324 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Damien Seguy 2001-07-12 12:49:04 +00:00
parent 4eecf267a0
commit f73e436d2b

View file

@ -1378,7 +1378,11 @@ echo "sum(b) = ".array_sum($b)."\n";
<function>array_unique</function> takes input
<parameter>array</parameter> and returns a new array
without duplicate values.
Note that keys are preserved.
</para>
<para>
Note that keys are preserved. <function>array_unique</function> will
keep the first key encountered for every value, and ignore all
following keys.
</para>
<para>
<example>
@ -1386,12 +1390,40 @@ echo "sum(b) = ".array_sum($b)."\n";
<programlisting role="php">
$input = array ("a" =&gt; "green", "red", "b" =&gt; "green", "blue", "red");
$result = array_unique ($input);
print_r($result);
// this will output :
//Array
//(
// [a] => green
// [0] => red
// [1] => blue
//)
</programlisting>
</example>
</para>
<para>
This makes <varname>$result</varname> have <literal>array ("a" =&gt;
"green", "red", "blue");</literal>.
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);
$result = array_unique ($input);
print_r($result);
// this will output :
//Array
//(
// [0] => 3
// [1] => 3
// [2] => 4
// [3] => 4
//)
</programlisting>
</example>
</para>
</refsect1>
</refentry>