downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  

<Errors and error handlingArrays and Array-style COM properties>
Last updated: Thu, 26 Jun 2008

Examples

Table of Contents

For Each

Starting with PHP 5, you may use PHP's own foreach statement to iterate over the contents of a standard COM/OLE IEnumVariant. In laymans terms, this means that you can use foreach in places where you would have used For Each in VB/ASP code.

Example #1 For Each in ASP

<%
Set domainObject = GetObject("WinNT://Domain")
For Each obj in domainObject
  Response.Write obj.Name & "<br />"
Next
%>

Example #2 while() ... Next() in PHP 4

<?php
$domainObject
= new COM("WinNT://Domain");
while (
$obj = $domainObject->Next()) {
   echo
$obj->Name . "<br />";
}
?>

Example #3 foreach in PHP 5

<?php
$domainObject
= new COM("WinNT://Domain");
foreach (
$domainObject as $obj) {
   echo
$obj->Name . "<br />";
}
?>



add a noteadd a note User Contributed Notes
Examples
There are no user contributed notes for this page.




<Errors and error handlingArrays and Array-style COM properties>
Last updated: Thu, 26 Jun 2008
show source | credits | sitemap | contact | advertising | mirror sites
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://phpbuilder.com/
Last updated: Tue Nov 1 20:20:59 2005 EST
Columns / Articles | Tips / Quickies | News | News Linking and RSS Feeds | Shared Code Library
Mail Archives | Support / Discussion Forums | Get Started! Links | Contribute! | Docs