1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-26 08:02:16 +01:00
Files
archived-doc-zh/reference/array/functions/compact.xml
Dai Jie 264ee58391 Sync array functions .
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@327980 c90b9560-bf6c-de11-be94-00142212c4b1
2012-10-10 12:54:58 +00:00

128 lines
3.5 KiB
XML
Executable File

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- $Author$ -->
<!-- EN-Revision: 96c9d88bad9a7d7d44bfb7f26c226df7ee9ddf26 Maintainer: dallas Status: ready -->
<refentry xml:id="function.compact" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>compact</refname>
<refpurpose>
建立一个数组,包括变量名和它们的值
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>array</type><methodname>compact</methodname>
<methodparam><type>mixed</type><parameter>varname</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
</methodsynopsis>
<para>
创建一个包含变量与其值的数组。
</para>
<para>
对每个参数,<function>compact</function>
在当前的符号表中查找该变量名并将它添加到输出的数组中,变量名成为键名而变量的内容成为该键的值。简单说,它做的事和
<function>extract</function> 正好相反。返回将所有变量添加进去后的数组。
</para>
<para>
任何没有变量名与之对应的字符串都被略过。
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>varname</parameter></term>
<listitem>
<para>
<function>compact</function> 接受可变的参数数目。每个参数可以是一个包括变量名的字符串或者是一个包含变量名的数组,该数组中还可以包含其它单元内容为变量名的数组,
<function>compact</function> 可以递归处理。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
返回输出的数组,包含了添加的所有变量。
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>compact</function> 例子</title>
<programlisting role="php">
<![CDATA[
<?php
$city = "San Francisco";
$state = "CA";
$event = "SIGGRAPH";
$location_vars = array("city", "state");
$result = compact("event", "nothing_here", $location_vars);
print_r($result);
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
Array
(
[event] => SIGGRAPH
[city] => San Francisco
[state] => CA
)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<title>Gotcha</title>
<para>
因为<link linkend="language.variables.variable">可变变量</link>也许不能在函数内部用于
PHP 的<link linkend="language.variables.superglobals">超全局数组</link>,此时不能将超全局数组传递入
<function>compact</function> 中。
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>extract</function></member>
</simplelist>
</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:"~/.phpdoc/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
-->