mirror of
https://github.com/php/doc-ja.git
synced 2026-03-26 16:12:17 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/ja/trunk@249547 c90b9560-bf6c-de11-be94-00142212c4b1
206 lines
6.2 KiB
XML
206 lines
6.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision: 1.12 $ -->
|
|
<!-- EN-Revision: 1.28 Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: shimooka -->
|
|
<refentry xml:id="function.array-walk" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_walk</refname>
|
|
<refpurpose>配列の全ての要素にユーザ関数を適用する</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>array_walk</methodname>
|
|
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
|
|
<methodparam><type>callback</type><parameter>funcname</parameter></methodparam>
|
|
<methodparam choice="opt"><type>mixed</type><parameter>userdata</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
<parameter>array</parameter> 配列の各要素にユーザ定義関数
|
|
<parameter>funcname</parameter> を適用します。
|
|
</simpara>
|
|
<para>
|
|
<function>array_walk</function> は <parameter>array</parameter>
|
|
の内部配列ポインタに影響されません。<function>array_walk</function>
|
|
はポインタの位置に関わらず配列の全てに渡って適用されます。
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
入力の配列。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>funcname</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
通常、
|
|
<parameter>funcname</parameter> は引数を二つとります。
|
|
<parameter>array</parameter> パラメータの値が最初の引数、
|
|
キー/添字は二番目の引数となります。
|
|
</para>
|
|
<note>
|
|
<para>
|
|
<parameter>funcname</parameter> により配列の値そのものを変更する必要がある場合、
|
|
<parameter>funcname</parameter> の最初の引数は
|
|
<link linkend="language.references">参照</link>
|
|
として渡す必要があります。この場合、配列の要素に加えた変更は、
|
|
配列自体に対して行われます。
|
|
</para>
|
|
</note>
|
|
<para>
|
|
コールバック関数により配列自身を変更することはできません。
|
|
例えば、要素の追加、削除、要素の unset 等はできません。
|
|
<function>array_walk</function> が適用される配列を
|
|
変更しようとすると、関数の動作を定義できず、
|
|
予期しない結果を得ることになります。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>userdata</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
オプションの <parameter>userdata</parameter> パラメータが指定された場合、
|
|
コールバック関数 <parameter>funcname</parameter>
|
|
への三番目の引数として渡されます。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success;
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
<parameter>funcname</parameter> 関数が、指定された引数より多いパラメータを必要とする
|
|
場合、<function>array_walk</function>が<parameter>funcname</parameter>
|
|
をコールする度にエラーレベル <link linkend="errorfunc.constants">E_WARNING</link> が
|
|
発生します。これらの警告は、<function>array_walk</function> コールの前に
|
|
PHP エラー演算子 <link linkend="language.operators.errorcontrol">@</link>
|
|
を付けるか、<function>error_reporting</function> により抑制することができます。
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>4.0.0</entry>
|
|
<entry>
|
|
キー及び <parameter>userdata</parameter>
|
|
を <parameter>funcname</parameter> に渡す処理が追加されました。
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>array_walk</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
|
|
|
|
function test_alter(&$item1, $key, $prefix)
|
|
{
|
|
$item1 = "$prefix: $item1";
|
|
}
|
|
|
|
function test_print($item2, $key)
|
|
{
|
|
echo "$key. $item2<br />\n";
|
|
}
|
|
|
|
echo "Before ...:\n";
|
|
array_walk($fruits, 'test_print');
|
|
|
|
array_walk($fruits, 'test_alter', 'fruit');
|
|
echo "... and after:\n";
|
|
|
|
array_walk($fruits, 'test_print');
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Before ...:
|
|
d. lemon
|
|
a. orange
|
|
b. banana
|
|
c. apple
|
|
... and after:
|
|
d. fruit: lemon
|
|
a. fruit: orange
|
|
b. fruit: banana
|
|
c. fruit: apple
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>array_walk_recursive</function></member>
|
|
<member><function>create_function</function></member>
|
|
<member><function>list</function></member>
|
|
<member><function>each</function></member>
|
|
<member><function>call_user_func_array</function></member>
|
|
<member><function>array_map</function></member>
|
|
<member>&seealso.callback;</member>
|
|
<member><link linkend="control-structures.foreach">foreach</link></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:"../../../../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
|
|
-->
|