2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 06:30:45 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.array-flip">
|
2006-10-31 11:24:02 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>array_flip</refname>
|
|
|
|
<refpurpose>Exchanges all keys with their associated values in an array</refpurpose>
|
|
|
|
</refnamediv>
|
2007-06-18 22:49:15 +00:00
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2006-10-31 11:24:02 +00:00
|
|
|
<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
|
|
|
|
order, i.e. keys from <parameter>trans</parameter> become values and values
|
|
|
|
from <parameter>trans</parameter> become keys.
|
|
|
|
</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>
|
2007-06-18 22:49:15 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>trans</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
An array of key/value pairs to be flipped.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
2010-01-07 20:19:16 +00:00
|
|
|
Returns the flipped array on success and &null; on failure.
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
2007-06-18 22:49:15 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>array_flip</function> example</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![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
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>array_flip</function> example : collision</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![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
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</programlisting>
|
|
|
|
<para>
|
|
|
|
now <varname>$trans</varname> is:
|
|
|
|
</para>
|
|
|
|
<screen>
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
|
|
|
Array
|
|
|
|
(
|
|
|
|
[1] => b
|
|
|
|
[2] => c
|
|
|
|
)
|
|
|
|
]]>
|
2006-10-31 11:24:02 +00:00
|
|
|
</screen>
|
|
|
|
</example>
|
|
|
|
</para>
|
2007-06-18 22:49:15 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2006-10-31 11:24:02 +00:00
|
|
|
<para>
|
2007-06-18 22:49:15 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>array_values</function></member>
|
|
|
|
<member><function>array_keys</function></member>
|
|
|
|
<member><function>array_reverse</function></member>
|
|
|
|
</simplelist>
|
2006-10-31 11:24:02 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- 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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2002-04-15 00:12:54 +00:00
|
|
|
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
|
|
|
|
-->
|