mirror of
https://github.com/php/doc-zh.git
synced 2026-03-26 08:02:16 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@94824 c90b9560-bf6c-de11-be94-00142212c4b1
89 lines
2.3 KiB
XML
Executable File
89 lines
2.3 KiB
XML
Executable File
<?xml version="1.0" encoding="gb2312"?>
|
|
<!-- $Revision: 1.1 $ -->
|
|
<!-- $Author: dallas $ -->
|
|
<!-- EN-Revision: 1.4 Maintainer: dallas Status: ready -->
|
|
<refentry id="function.array-flip">
|
|
<refnamediv>
|
|
<refname>array_flip</refname>
|
|
<refpurpose>反转数组中的键和值</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>说明</title>
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array_flip</methodname>
|
|
<methodparam><type>array</type><parameter>trans</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array_flip</function> 返回一个反转后的 <type>array</type>,例如
|
|
<parameter>trans</parameter> 中的键名变成了值,而
|
|
<parameter>trans</parameter> 中的值成了键名。
|
|
</para>
|
|
<para>
|
|
注意 <parameter>trans</parameter> 中的值需要能够作为合法的键名,例如需要是
|
|
<type>integer</type> 或者 <type>string</type>。如果值的类型不对将发出一个警告,并且有问题的键/值对<emphasis>将不会反转</emphasis>。
|
|
</para>
|
|
<para>
|
|
如果同一个值出现了多次,则最后一个键名将作为它的值,所有其它的都丢失了。
|
|
</para>
|
|
<para>
|
|
<function>array_flip</function> 如果失败返回 &false;。
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>array_flip</function> 例子</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
$trans = array_flip ($trans);
|
|
$original = strtr ($str, $trans);
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>array_flip</function> 例子:冲突</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
$trans = array ("a" => 1, "b" => 1, "c" => 2);
|
|
$trans = array_flip ($trans);
|
|
print_r($trans);
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
现在 $trans 变成了:
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => b
|
|
[2] => c
|
|
)
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</example>
|
|
</para>
|
|
</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
|
|
-->
|