mirror of
https://github.com/php/doc-ja.git
synced 2026-03-25 15:42:08 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@329670 c90b9560-bf6c-de11-be94-00142212c4b1
218 lines
5.2 KiB
XML
218 lines
5.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 8f8fb2bd4d9819bec5b9c2c9ca835c884aac5ea7 Maintainer: hirokawa Status: ready -->
|
|
<refentry xml:id="function.list" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>list</refname>
|
|
<refpurpose>配列と同様の形式で、複数の変数への代入を行う</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>list</methodname>
|
|
<methodparam><type>mixed</type><parameter>varname</parameter></methodparam>
|
|
<methodparam rep="repeat" choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array</function> と同様に、
|
|
この関数は実際には関数ではなく言語構造です。
|
|
<function>list</function> は、
|
|
単一の操作で一連の変数に値を代入するために使われます。
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>varname</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
変数。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
代入した配列を返します。
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>list</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$info = array('コーヒー', '茶色', 'カフェイン');
|
|
|
|
// すべての変数の取得
|
|
list($drink, $color, $power) = $info;
|
|
echo "$drink の色は $color で、$power が含まれています。\n";
|
|
|
|
// 一部の変数の取得
|
|
list($drink, , $power) = $info;
|
|
echo "$drink には $power が含まれています。\n";
|
|
|
|
// 三番目のみの取得
|
|
list( , , $power) = $info;
|
|
echo "$power 欲しい!\n";
|
|
|
|
// list() は文字列では動作しません
|
|
list($bar) = "abcde";
|
|
var_dump($bar); // NULL
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>list</function> の使用法の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<table>
|
|
<tr>
|
|
<th>社員氏名</th>
|
|
<th>給与</th>
|
|
</tr>
|
|
|
|
<?php
|
|
$result = $pdo->query("SELECT id, name, salary FROM employees");
|
|
while (list($id, $name, $salary) = $result->fetch(PDO::FETCH_NUM)) {
|
|
echo " <tr>\n" .
|
|
" <td><a href=\"info.php?id=$id\">$name</a></td>\n" .
|
|
" <td>$salary</td>\n" .
|
|
" </tr>\n";
|
|
}
|
|
|
|
?>
|
|
|
|
</table>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>ネストした <function>list</function> の使用法</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
list($a, list($b, $c)) = array(1, array(2, 3));
|
|
|
|
var_dump($a, $b, $c);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<screen>
|
|
<![CDATA[
|
|
int(1)
|
|
int(2)
|
|
int(3)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>配列の添字を使用した <function>list</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$info = array('coffee', 'brown', 'caffeine');
|
|
|
|
list($a[0], $a[1], $a[2]) = $info;
|
|
|
|
var_dump($a);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
次のような出力になります(<function>list</function> の文法に書かれた
|
|
順番と、要素の順番の違いに注意):
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
array(3) {
|
|
[2]=>
|
|
string(8) "caffeine"
|
|
[1]=>
|
|
string(5) "brown"
|
|
[0]=>
|
|
string(6) "coffee"
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<warning>
|
|
<para>
|
|
<function>list</function>は、最も右のパラメータから値を代入します。
|
|
プレーンな変数を使用している場合には、このことを気にする必要はありません。
|
|
しかし、添字配列を使用している場合には、配列の添字の順番が
|
|
<function>list</function>
|
|
に書いたものと同じく左から右となることを通常は期待しますが、
|
|
そうはなりません。この配列の添字は逆の順番となります。
|
|
</para>
|
|
</warning>
|
|
<warning>
|
|
<para>
|
|
<function>list</function> を実行して配列を変更
|
|
(<literal>list($a, $b) = $b</literal> など)
|
|
した場合の挙動は未定義です。
|
|
</para>
|
|
</warning>
|
|
<note>
|
|
<para>
|
|
<function>list</function> は数値添字の配列のみを生成します。
|
|
添字は 0 から始まります。
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>each</function></member>
|
|
<member><function>array</function></member>
|
|
<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
|
|
-->
|