1
0
mirror of https://github.com/php/doc-zh.git synced 2026-03-27 00:22:13 +01:00
Files
archived-doc-zh/reference/array/functions/compact.xml
Dallas Wang 9912944367 Translation completed.
git-svn-id: https://svn.php.net/repository/phpdoc/zh/trunk@95633 c90b9560-bf6c-de11-be94-00142212c4b1
2002-09-13 03:20:17 +00:00

86 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.compact">
<refnamediv>
<refname>compact</refname>
<refpurpose>
建立一个数组,包括变量名和它们的值
</refpurpose>
</refnamediv>
<refsect1>
<title>说明</title>
<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>
<function>compact</function> 接受可变的参数数目。每个参数可以是一个包括变量名的字符串或者是一个包含变量名的数组,该数组中还可以包含其它单元内容为变量名的数组,
<function>compact</function> 可以递归处理。
</para>
<para>
对每个参数,<function>compact</function>
在当前的符号表中查找该变量名并将它添加到输出的数组中,变量名成为键名而变量的内容成为该键的值。简单说,它做的事和
<function>extract</function> 正好相反。返回将所有变量添加进去后的数组。
</para>
<para>
任何没有设定为变量名的字符串都被跳过。
</para>
<para>
<example>
<title><function>compact</function> 例子</title>
<programlisting role="php">
<![CDATA[
$city = "San Francisco";
$state = "CA";
$event = "SIGGRAPH";
$location_vars = array ("city", "state");
$result = compact ("event", "nothing_here", $location_vars);
]]>
</programlisting>
<para>
经过处理后,<varname>$result</varname> 为:
<screen role="php">
<![CDATA[
Array
(
[event] => SIGGRAPH
[city] => San Francisco
[state] => CA
)
]]>
</screen>
</para>
</example>
</para>
<para>
参见 <function>extract</function>
</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
-->