For Each

Vous pouvez utiliser la structure de contrôle foreach de PHP pour passer 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 For Each dans du code VB/ASP.

Exemple #1 For Each en ASP

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

Exemple #2 Foreach en PHP

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

add a note add a note

User Contributed Notes 1 note

up
0
szir at sch dot bme dot hu
13 years ago
As described in the PHP 5 COM changes article: http://devzone.zend.com/node/view/id/762
You not just "may use foreach statement", but you have to, because $domainObject->Next() is not available in PHP 5 (syntax has been dropped, not backwards compatible)
To Top