array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'es', ), 'this' => array ( 0 => 'com.examples.foreach.php', 1 => 'For Each', ), 'up' => array ( 0 => 'com.examples.php', 1 => 'Ejemplos', ), 'prev' => array ( 0 => 'com.examples.php', 1 => 'Ejemplos', ), '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', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
You may use PHP's own
foreach statement to iterate
over the contents of a standard COM/OLE IEnumVariant. In layman's terms,
this means that you can use foreach in places where you would have used
For Each
in VB/ASP code.
Ejemplo #1 For Each in ASP
<% Set domainObject = GetObject("WinNT://Domain") For Each obj in domainObject Response.Write obj.Name & "<br />" Next %>
Ejemplo #2 foreach in PHP
<?php
$domainObject = new COM("WinNT://Domain");
foreach ($domainObject as $obj) {
echo $obj->Name . "<br />";
}
?>