1
0
mirror of https://github.com/php/doc-ja.git synced 2026-03-26 16:12:17 +01:00
Files
archived-doc-ja/reference/array/functions/list.xml
Tadashi Jokagi a.k.a. "ELF" or "Joe 0310373bb8 o Sync with en.
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@185442 c90b9560-bf6c-de11-be94-00142212c4b1
2005-04-29 10:57:49 +00:00

155 lines
3.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.6 $ -->
<!-- EN-Revision: 1.14 Maintainer: hirokawa Status: ready -->
<refentry id="function.list">
<refnamediv>
<refname>list</refname>
<refpurpose>
配列と同様の形式で、複数の変数への代入を行います
</refpurpose>
</refnamediv>
<refsect1>
<title>説明</title>
<methodsynopsis>
<type>void</type><methodname>list</methodname>
<methodparam rep="repeat"><type>mixed</type><parameter>...</parameter></methodparam>
<methodparam rep="repeat"><type>mixed</type><parameter>...</parameter></methodparam>
</methodsynopsis>
<para>
<function>array</function> と同様に、
この関数は実際には関数ではなく言語の構成要素です。
<function>list</function> は、
単一の操作で一連の変数に値を割り当てるために使われます。
</para>
<note>
<para>
<function>list</function> は数値添字の配列のみを生成します。
添字は 0 から始まります。
</para>
</note>
<para>
<example>
<title><function>list</function> の例</title>
<programlisting role="php">
<![CDATA[
<?php
$info = array('coffee', 'brown', 'caffeine');
// Listing all the variables
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.\n";
// Listing some of them
list($drink, , $power) = $info;
echo "$drink has $power.\n";
// Or let's skip to only the third one
list( , , $power) = $info;
echo "I need $power!\n";
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title><function>list</function> の使用法の例</title>
<programlisting role="php">
<![CDATA[
<table>
<tr>
<th>社員氏名</th>
<th>給与</th>
</tr>
<?php
$result = mysql_query("SELECT id, name, salary FROM employees", $conn);
while (list($id, $name, $salary) = mysql_fetch_row($result)) {
echo " <tr>\n" .
" <td><a href=\"info.php?id=$id\">$name</a></td>\n" .
" <td>$salary</td>\n" .
" </tr>\n";
}
?>
</table>
]]>
</programlisting>
</example>
</para>
<warning>
<para>
<function>list</function>は、最も右のパラメータから値を代入します。
プレーンな変数を使用している場合には、このことを気にする必要はありません。
しかし、添字配列を使用している場合には、配列の添字の順番が
<function>list</function>
に書いたものと同じく左から右となることを通常は期待しますが、
そうはなりません。この配列の添字は逆の順番となります。
</para>
</warning>
<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>
<para>
<function>each</function><function>array</function>
<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
-->