mirror of
https://github.com/php/doc-ja.git
synced 2026-03-25 23:52:16 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@185760 c90b9560-bf6c-de11-be94-00142212c4b1
102 lines
3.1 KiB
XML
102 lines
3.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision: 1.6 $ -->
|
|
<!-- EN-Revision: 1.8 Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: shimooka -->
|
|
<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>
|
|
<note>
|
|
<title>分かった!</title>
|
|
<para>
|
|
<link linkend="language.variables.variable">可変変数</link> は関数内で
|
|
PHP の <link linkend="language.variables.superglobals">
|
|
スーパーグローバル配列</link> と併用してはいけませんので、
|
|
スーパーグローバル配列を <function>compact</function> に渡しては
|
|
いけません。
|
|
</para>
|
|
</note>
|
|
<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);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
この例により、<varname>$result</varname>は以下のようになります:
|
|
</para>
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[event] => SIGGRAPH
|
|
[city] => San Francisco
|
|
[state] => CA
|
|
)
|
|
]]>
|
|
</screen>
|
|
</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
|
|
-->
|