mirror of
https://github.com/php/doc-fr.git
synced 2026-03-24 15:12:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@351882 c90b9560-bf6c-de11-be94-00142212c4b1
230 lines
6.1 KiB
XML
230 lines
6.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: cd943f94a013b74df8765ab8e1a620a916a64a85 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<!-- CREDITS: DavidA. -->
|
|
|
|
<refentry xml:id="function.array-slice" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_slice</refname>
|
|
<refpurpose>Extrait une portion de tableau</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> retourne une série d'éléments
|
|
du tableau <parameter>array</parameter> commençant à
|
|
l'offset <parameter>offset</parameter> et représentant
|
|
<parameter>length</parameter> éléments.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>array</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Le tableau d'entrée.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>offset</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si <parameter>offset</parameter> est non-négatif, la séquence
|
|
commencera à cette position dans le tableau <parameter>array</parameter>.
|
|
</para>
|
|
<para>
|
|
Si <parameter>offset</parameter> est négatif, la séquence
|
|
commencera à la position <parameter>offset</parameter>, mais en
|
|
commençant à la fin du tableau <parameter>array</parameter>.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Le paramètre <parameter>offset</parameter> indique la position
|
|
dans le tableau, pas la clé.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>length</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si <parameter>length</parameter> est fourni et positif, alors
|
|
la séquence aura jusqu'à autant d'éléments.
|
|
</para>
|
|
<para>
|
|
Si le tableau plus court que <parameter>length</parameter>,
|
|
alors seuls les éléments du &array; disponible seront présents.
|
|
</para>
|
|
<para>
|
|
Si <parameter>length</parameter> est fourni et négatif, alors
|
|
la séquence contiendra autant d'éléments de la fin du &array;.
|
|
</para>
|
|
<para>
|
|
Si il est omis, la séquence aura tout
|
|
depuis la position <parameter>offset</parameter> jusqu'à la fin de
|
|
<parameter>array</parameter>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>preserve_keys</parameter></term>
|
|
<listitem>
|
|
<note>
|
|
<para>
|
|
Par défaut <function>array_slice</function> réordonnera et réinitialisera
|
|
les indices entier du &array;.
|
|
Ce comportement peut être modifié en définissant le paramètre
|
|
<parameter>preserve_keys</parameter> à &true;.
|
|
Les clés sous forme de &string; sont toujours conservées,
|
|
indépendamment de ce paramètre.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Retourne la portion du tableau. Si la position est plus grande
|
|
que la taille du &array;, un &array; vide est retourné.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <function>array_slice</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$input = array("a", "b", "c", "d", "e");
|
|
|
|
$output = array_slice($input, 2); // retourne "c", "d", et "e"
|
|
$output = array_slice($input, -2, 1); // retourne "d"
|
|
$output = array_slice($input, 0, 3); // retourne "a", "b", et "c"
|
|
|
|
// notez les clés d'index différentes
|
|
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> et basé sur un tableau</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> et tableau avec des clés mixtes</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
|
|
--> |