2002-05-12 08:19:28 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2003-08-17 12:21:03 +00:00
|
|
|
<!-- $Revision: 1.11 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- splitted from ./en/functions/array.xml, last change in rev 1.107 -->
|
|
|
|
<refentry id="function.array-flip">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>array_flip</refname>
|
2002-12-22 21:29:56 +00:00
|
|
|
<refpurpose>Exchanges all keys with their associated values in an array</refpurpose>
|
2002-04-15 00:12:54 +00:00
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
<methodsynopsis>
|
|
|
|
<type>array</type><methodname>array_flip</methodname>
|
|
|
|
<methodparam><type>array</type><parameter>trans</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
<function>array_flip</function> returns an <type>array</type> in flip
|
2003-05-03 21:54:11 +00:00
|
|
|
order, i.e. keys from <parameter>trans</parameter> become values and values
|
|
|
|
from <parameter>trans</parameter> become keys.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Note that the values of <parameter>trans</parameter> need to be valid
|
|
|
|
keys, i.e. they need to be either <type>integer</type> or
|
|
|
|
<type>string</type>. A warning will be emitted if a value has the wrong
|
|
|
|
type, and the key/value pair in question <emphasis>will not be
|
|
|
|
flipped</emphasis>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If a value has several occurrences, the latest key will be
|
|
|
|
used as its values, and all others will be lost.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<function>array_flip</function> returns &false;
|
|
|
|
if it fails.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>array_flip</function> example</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2003-05-30 18:12:53 +00:00
|
|
|
<?php
|
2003-08-17 12:21:03 +00:00
|
|
|
$trans = array_flip($trans);
|
|
|
|
$original = strtr($str, $trans);
|
2003-05-30 18:12:53 +00:00
|
|
|
?>
|
2002-04-15 00:12:54 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>array_flip</function> example : collision</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
2003-05-30 18:12:53 +00:00
|
|
|
<?php
|
2003-08-17 12:21:03 +00:00
|
|
|
$trans = array("a" => 1, "b" => 1, "c" => 2);
|
|
|
|
$trans = array_flip($trans);
|
2002-04-15 00:12:54 +00:00
|
|
|
print_r($trans);
|
2003-05-30 18:12:53 +00:00
|
|
|
?>
|
2002-04-15 00:12:54 +00:00
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
<para>
|
2003-06-16 12:03:39 +00:00
|
|
|
now <varname>$trans</varname> is:
|
|
|
|
</para>
|
|
|
|
<screen>
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
|
|
|
Array
|
|
|
|
(
|
|
|
|
[1] => b
|
|
|
|
[2] => c
|
|
|
|
)
|
|
|
|
]]>
|
2003-06-16 12:03:39 +00:00
|
|
|
</screen>
|
2002-04-15 00:12:54 +00:00
|
|
|
</example>
|
|
|
|
</para>
|
2003-07-17 22:38:54 +00:00
|
|
|
<para>
|
|
|
|
See also <function>array_values</function>,
|
|
|
|
<function>array_keys</function>, and
|
|
|
|
<function>array_reverse</function>.
|
|
|
|
</para>
|
2002-04-15 00:12:54 +00:00
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|