mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 15:12:22 +01:00
220 lines
6.1 KiB
XML
220 lines
6.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: cd943f94a013b74df8765ab8e1a620a916a64a85 Maintainer: takagi Status: ready -->
|
|
<!-- CREDITS: hirokawa,mumumu -->
|
|
<refentry xml:id="function.array-slice" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_slice</refname>
|
|
<refpurpose>配列の一部を展開する</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array_slice</methodname>
|
|
<methodparam><type>array</type><parameter>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>bool</type><parameter>preserve_keys</parameter><initializer>&false;</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>array_slice</function>は、<parameter>array</parameter>
|
|
から引数 <parameter>offset</parameter> および
|
|
<parameter>length</parameter> で指定された連続する要素を返します。
|
|
</para>
|
|
</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> の offset から始められます。
|
|
</para>
|
|
<para>
|
|
<parameter>offset</parameter> が負の場合、要素位置の計算は
|
|
<parameter>array</parameter> の最後から行われます。
|
|
</para>
|
|
<para>
|
|
<parameter>offset</parameter> は、配列の位置を表します。配列のキーではありません。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>length</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<parameter>length</parameter>が指定され、正の場合、
|
|
配列の要素の中から最大でその数までの要素を返します。
|
|
</para>
|
|
<para>
|
|
配列の要素数が <parameter>length</parameter> より少ない場合は、
|
|
配列から取得できる要素だけを返します。
|
|
</para>
|
|
<para>
|
|
<parameter>length</parameter>
|
|
が指定され、負の場合、配列の末尾からその数だけ要素を取り除いた配列が返されます。
|
|
</para>
|
|
<para>
|
|
省略された場合、<parameter>offset</parameter>
|
|
から配列の最後までの全ての要素が返されます。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>preserve_keys</parameter></term>
|
|
<listitem>
|
|
<note>
|
|
<para>
|
|
<function>array_slice</function> はデフォルトで配列の数値キーを並べなおし、
|
|
リセットします。
|
|
<parameter>preserve_keys</parameter> を &true;
|
|
にする事でこの動作を変更することができます。
|
|
文字列のキーは、このパラメータの値にかかわらず常に保存されます。
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
切り取った部分を返します。オフセットが配列のサイズより大きい場合は、空の配列を返します。
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>array_slice</function> の例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$input = array("a", "b", "c", "d", "e");
|
|
|
|
$output = array_slice($input, 2); // "c", "d", "e" を返す
|
|
$output = array_slice($input, -2, 1); // "d" を返す
|
|
$output = array_slice($input, 0, 3); // "a", "b", "c" を返す
|
|
|
|
// 配列キーの違いに注意
|
|
print_r(array_slice($input, 2, -1));
|
|
print_r(array_slice($input, 2, -1, true));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => c
|
|
[1] => d
|
|
)
|
|
Array
|
|
(
|
|
[2] => c
|
|
[3] => d
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>array_slice</function> と、キーが1から始まる配列</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$input = array(1 => "a", "b", "c", "d", "e");
|
|
print_r(array_slice($input, 1, 2));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => b
|
|
[1] => c
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>array_slice</function> に、数値と文字列のキーが混じった配列を渡す例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$ar = array('a'=>'apple', 'b'=>'banana', '42'=>'pear', 'd'=>'orange');
|
|
print_r(array_slice($ar, 0, 3));
|
|
print_r(array_slice($ar, 0, 3, true));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[a] => apple
|
|
[b] => banana
|
|
[0] => pear
|
|
)
|
|
Array
|
|
(
|
|
[a] => apple
|
|
[b] => banana
|
|
[42] => pear
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>array_chunk</function></member>
|
|
<member><function>array_splice</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
|
|
-->
|