mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-23 22:52:12 +01:00
99 lines
2.6 KiB
XML
99 lines
2.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 28f122648d4f4b0c23d36dbfb5950da50c501b18 Maintainer: leonardolara Status: ready -->
|
|
|
|
<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>
|
|
Pode-se usar a instrução
|
|
&foreach; do próprio PHP para iterar
|
|
sobre o conteúdo de um IEnumVariant COM/OLE padrão. Em termos leigos,
|
|
isso significa o foreach pode ser usado em lugares onde
|
|
<literal>For Each</literal> teria sido usado no código VB/ASP.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>For Each em 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>foreach no PHP</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>Arrays e propriedades COM no estilo Array</title>
|
|
<para>
|
|
Muitos objetos COM expõem suas propriedades como arrays ou usando acesso
|
|
no estilo de array.
|
|
</para>
|
|
<para>
|
|
É possível:
|
|
<itemizedlist>
|
|
<listitem>
|
|
<para>
|
|
Acessar arrays multidimensionais ou propriedades COM que exigem
|
|
múltiplos parâmetros usando a sintaxe de array do PHP. Pode-se também escrever ou definir
|
|
propriedades usando esta técnica.
|
|
</para>
|
|
</listitem>
|
|
<listitem>
|
|
<para>
|
|
Iterar sobre SafeArrays (arrays "verdadeiros") usando a estrutura de controle &foreach;.
|
|
Isso funciona porque os SafeArrays incluem informações sobre seu tamanho. Se uma
|
|
propriedade no estilo array implementar IEnumVariant, pode-se também poderá usar
|
|
foreach para essa propriedade; consulte <xref
|
|
linkend="com.examples.foreach"/> para obter mais informações sobre este tópico.
|
|
</para>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
</section>
|
|
|
|
</chapter>
|
|
|
|
<!-- 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
|
|
-->
|