mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-26 18:02:17 +01:00
UTF-8 => ISO-8859-1 git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@261457 c90b9560-bf6c-de11-be94-00142212c4b1
102 lines
3.1 KiB
XML
102 lines
3.1 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.3 $ -->
|
|
<!-- EN-Revision: 1.2 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
|
|
<chapter xml:id="com.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
&reftitle.examples;
|
|
|
|
<section xml:id="com.examples.foreach">
|
|
<title>For Each</title>
|
|
<para>
|
|
Avec PHP 5, vous pouvez utiliser la structure de contrôle <link
|
|
linkend="control-structures.foreach">foreach</link> de PHP pour passe en
|
|
boucle à travers le contenu d'un IEnumVariant COM/OLE standard.
|
|
Cela signifie que vous pouvez utiliser foreach aux endroits où
|
|
vous auriez pu utiliser <literal>For Each</literal> dans du code VB/ASP.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>For Each en ASP</title>
|
|
<programlisting role="asp">
|
|
<![CDATA[
|
|
<%
|
|
Set domainObject = GetObject("WinNT://Domain")
|
|
For Each obj in domainObject
|
|
Response.Write obj.Name & "<br />"
|
|
Next
|
|
%>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>while() ... Next() en PHP 4</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$domainObject = new COM("WinNT://Domain");
|
|
while ($obj = $domainObject->Next()) {
|
|
echo $obj->Name . "<br />";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>foreach en PHP 5</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$domainObject = new COM("WinNT://Domain");
|
|
foreach ($domainObject as $obj) {
|
|
echo $obj->Name . "<br />";
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</section>
|
|
|
|
<section xml:id="com.examples.arrays">
|
|
<title>Tableaux et propriétés à la façon des tableaux de COM</title>
|
|
<para>
|
|
Plusieurs objets COM exposent leurs propriétés comme tableaux, ou en
|
|
utilisant un chemin d'accès à la façon des tableaux. En PHP 4, vous
|
|
pouvez utiliser la syntaxe de tableaux de PHP pour lire/écrire une
|
|
propriété de ce genre, mais une seule dimension est permise. Si vous
|
|
voulez lire une propriété multidimensionnelle, vous pouvez y accéder
|
|
à travers une fonction ou chaque paramètre représente
|
|
une dimension de ce tableau, mais il n'y a aucun moyen d'écrire une
|
|
telle propriété.
|
|
</para>
|
|
<para>
|
|
PHP 5 introduit différentes nouvelles fonctionnalités pour vous
|
|
faciliter la vie:
|
|
<itemizedlist>
|
|
<listitem>
|
|
<para>
|
|
Accédez aux tableaux multidimensionnels ou aux propriétés COM qui
|
|
requièrent plusieurs paramètres comme si vous accédiez à un tableau.
|
|
Vous pouvez aussi écrire ces propriétés en utilisant cette technique.
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
Bouclez sur les SafeArrays ("vrais" tableaux) en utilisant la structure
|
|
de contrôle <xref linkend="control-structures.foreach"/>. Cela fonctionne
|
|
car un SafeArrays comporte des informations à propos de sa taille. Si
|
|
une propriété à la façon des tableaux implémente IEnumVariant, alors vous
|
|
pouvez aussi utiliser foreach pour cette propriété ; lisez <xref
|
|
linkend="com.examples.foreach"/> pour plus d'informations à ce sujet.
|
|
</para>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
</section>
|
|
|
|
</chapter> |