<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/com.examples.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'com.examples.foreach.php',
    1 => 'For Each',
    2 => 'For Each',
  ),
  'up' => 
  array (
    0 => 'com.examples.php',
    1 => 'Esempi',
  ),
  'prev' => 
  array (
    0 => 'com.examples.php',
    1 => 'Esempi',
  ),
  'next' => 
  array (
    0 => 'com.examples.arrays.php',
    1 => 'Arrays and Array-style COM properties',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/com/examples.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="com.examples.foreach" class="section">
  <h2 class="title">For Each</h2>
  <p class="para">
   You may use PHP&#039;s own 
   <a href="control-structures.foreach.php" class="link">foreach</a> statement to iterate
   over the contents of a standard COM/OLE IEnumVariant.  In layman&#039;s terms,
   this means that you can use foreach in places where you would have used
   <code class="literal">For Each</code> in VB/ASP code.
  </p>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 For Each in ASP</strong></p>
    <div class="example-contents">
<div class="aspcode"><pre class="aspcode">&lt;%
Set domainObject = GetObject(&quot;WinNT://Domain&quot;)
For Each obj in domainObject
  Response.Write obj.Name &amp; &quot;&lt;br /&gt;&quot;
Next
%&gt;</pre>
</div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 foreach in PHP</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php <br />$domainObject </span><span style="color: #007700">= new </span><span style="color: #0000BB">COM</span><span style="color: #007700">(</span><span style="color: #DD0000">"WinNT://Domain"</span><span style="color: #007700">); <br />foreach (</span><span style="color: #0000BB">$domainObject </span><span style="color: #007700">as </span><span style="color: #0000BB">$obj</span><span style="color: #007700">) { <br />   echo </span><span style="color: #0000BB">$obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">Name </span><span style="color: #007700">. </span><span style="color: #DD0000">"&lt;br /&gt;"</span><span style="color: #007700">; <br />} <br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div><?php manual_footer($setup); ?>