-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathcompact.xml
executable file
·167 lines (159 loc) · 4.62 KB
/
compact.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: d58ee8eaaa7f716c51f66f5f1058ab3c42376d98 Maintainer: daijie Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<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 class="union"><type>array</type><type>string</type></type><parameter>var_name</parameter></methodparam>
<methodparam rep="repeat"><type class="union"><type>array</type><type>string</type></type><parameter>var_names</parameter></methodparam>
</methodsynopsis>
<para>
创建一个包含变量与其值的数组。
</para>
<para>
对每个参数,<function>compact</function>
在当前的<link linkend="features.gc.refcounting-basics">符号表</link>中查找该变量名并将它添加到输出的数组中,
变量名成为键名而变量的内容成为该键的值。简单说,它做的事和
<function>extract</function> 正好相反。返回将所有变量添加进去后的数组。
</para>
<note>
<para>
在 PHP 7.3 之前版本,未设置的字符串会被静默忽略。
</para>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>var_name</parameter></term>
<term><parameter>var_names</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="errors">
&reftitle.errors;
<para>
如果字符串指向的变量未定义,<function>compact</function> 会产生 <constant>E_WARNING</constant> 级别的错误。
</para>
</refsect1>
<refsect1 role="changelog"><!-- {{{ -->
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
如果指定字符串引用了未设置的变量,现在会发出 <constant>E_WARNING</constant> 级别的错误。
</entry>
</row>
<row>
<entry>7.3.0</entry>
<entry>
现在,如果字符串指向的变量未定义,<function>compact</function> 会产生 <constant>E_NOTICE</constant>
级错误。在此之前,这样的字符串会默默地跳过。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</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", $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
-->