mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 15:12:22 +01:00
278 lines
8.1 KiB
XML
278 lines
8.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 2e60c5134e7a847c99f81eb3f7ecee1f5efeeace Maintainer: hirokawa Status: ready -->
|
|
<!-- CREDITS: shimooka,takagi,mumumu -->
|
|
<refentry xml:id="function.array-splice" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_splice</refname>
|
|
<refpurpose>配列の一部を削除し、他の要素で置換する</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array_splice</methodname>
|
|
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
|
|
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
|
|
<methodparam choice="opt"><type class="union"><type>int</type><type>null</type></type><parameter>length</parameter><initializer>&null;</initializer></methodparam>
|
|
<methodparam choice="opt"><type>mixed</type><parameter>replacement</parameter><initializer>[]</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
配列 <parameter>array</parameter>
|
|
から <parameter>offset</parameter> および <parameter>length</parameter>
|
|
で指定された要素を削除し、配列 <parameter>replacement</parameter>
|
|
でそれを置換します。
|
|
</para>
|
|
<note>
|
|
<para>
|
|
<parameter>array</parameter> の配列の数値添字は保存されないことに注意しましょう。
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<simpara>
|
|
<parameter>replacement</parameter> が配列でない場合は、
|
|
<link linkend="language.types.array.casting">型変換</link>
|
|
を行います (つまり <code>(array) $replacement</code> とします)。
|
|
たとえば <parameter>replacement</parameter> にオブジェクトや &null; などを指定した場合に、
|
|
予期せぬ動きをする可能性があります。
|
|
</simpara>
|
|
</note>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
入力の配列。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>offset</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<parameter>offset</parameter> が正の場合、削除される部分は
|
|
配列 <parameter>array</parameter> の最初から指定オフセットの
|
|
ぶんだけ進んだ位置からとなります。
|
|
</para>
|
|
<para>
|
|
<parameter>offset</parameter> が負の場合、削除される部分は、
|
|
<parameter>array</parameter> の末尾から数えた位置からとなります。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>length</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<parameter>length</parameter> が省略された場合、
|
|
<parameter>offset</parameter> から配列の最後までが全て削除されます。
|
|
</para>
|
|
<para>
|
|
<parameter>length</parameter> が指定され、正の場合、複数の要素が削除されます。
|
|
</para>
|
|
<para>
|
|
負の <parameter>length</parameter> が指定された場合、削除される部分の末尾の位置は配列の末尾を基準にして計算されます。
|
|
</para>
|
|
<para>
|
|
<parameter>length</parameter> にゼロを指定した場合は、どの要素も削除しません。
|
|
</para>
|
|
<tip>
|
|
<para>
|
|
<parameter>replacement</parameter> も指定した場合に
|
|
<parameter>offset</parameter> から配列の最後まで全てを削除するには、
|
|
<parameter>length</parameter> を求めるために <literal>count($input)
|
|
</literal> を使用してください。
|
|
</para>
|
|
</tip>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>replacement</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
配列 <parameter>replacement</parameter> が指定された場合、
|
|
削除された要素は、この配列の要素で置換されます。
|
|
</para>
|
|
<para>
|
|
<parameter>offset</parameter> および <parameter>length</parameter>
|
|
で何も削除しないと指定した場合、配列 <parameter>replacement</parameter>
|
|
の要素は <parameter>offset</parameter> で指定された位置に挿入されます。
|
|
</para>
|
|
<note>
|
|
<para>
|
|
置換される配列のキーは保存されないことに注意してください。
|
|
</para>
|
|
</note>
|
|
<para>
|
|
もし <parameter>replacement</parameter> に一つしか要素がない場合、
|
|
要素そのものが配列やオブジェクトあるいは &null; でない限り、<literal>array()</literal>
|
|
や 角括弧 で括る必要はありません。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
抽出された要素を含む配列を返します。
|
|
</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>
|
|
<parameter>length</parameter> は、nullable になりました。
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>array_splice</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$input = array("red", "green", "blue", "yellow");
|
|
array_splice($input, 2);
|
|
var_dump($input);
|
|
|
|
$input = array("red", "green", "blue", "yellow");
|
|
array_splice($input, 1, -1);
|
|
var_dump($input);
|
|
|
|
$input = array("red", "green", "blue", "yellow");
|
|
array_splice($input, 1, count($input), "orange");
|
|
var_dump($input);
|
|
|
|
$input = array("red", "green", "blue", "yellow");
|
|
array_splice($input, -1, 1, array("black", "maroon"));
|
|
var_dump($input);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(2) {
|
|
[0]=>
|
|
string(3) "red"
|
|
[1]=>
|
|
string(5) "green"
|
|
}
|
|
array(2) {
|
|
[0]=>
|
|
string(3) "red"
|
|
[1]=>
|
|
string(6) "yellow"
|
|
}
|
|
array(2) {
|
|
[0]=>
|
|
string(3) "red"
|
|
[1]=>
|
|
string(6) "orange"
|
|
}
|
|
array(5) {
|
|
[0]=>
|
|
string(3) "red"
|
|
[1]=>
|
|
string(5) "green"
|
|
[2]=>
|
|
string(4) "blue"
|
|
[3]=>
|
|
string(5) "black"
|
|
[4]=>
|
|
string(6) "maroon"
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>同じ動きをする、<function>array_splice</function> の様々な例</title>
|
|
<para>
|
|
以下の文は、すべて2つとも同じ意味です:
|
|
</para>
|
|
<programlisting role="php" annotations="non-interactive">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
// $input に 2 つの要素を追加します
|
|
array_push($input, $x, $y);
|
|
array_splice($input, count($input), 0, array($x, $y));
|
|
|
|
// $input の最後の要素を削除します
|
|
array_pop($input);
|
|
array_splice($input, -1);
|
|
|
|
// $input の最初の要素を削除します
|
|
array_shift($input);
|
|
array_splice($input, 0, 1);
|
|
|
|
// $input の先頭に要素を挿入します
|
|
array_unshift($input, $x, $y);
|
|
array_splice($input, 0, 0, array($x, $y));
|
|
|
|
// インデックス $x の $input を置き換えます
|
|
$input[$x] = $y; // キーがオフセットと等価な配列に対して
|
|
array_splice($input, $x, 1, $y);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>array_merge</function></member>
|
|
<member><function>array_slice</function></member>
|
|
<member><function>unset</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
|
|
-->
|