PHP Velho Oeste 2024

For Each

標準的な COM/OLE IEnumVariant の内容について、 PHP の foreach 命令を使用した反復処理を行うことができます。分かりやすく言うと、 これは、VB/ASP のコードで For Each を使用できる場所には foreach を使用できるということを意味します。

例1 ASP における For Each

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

例2 PHP 5 における foreach

<?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
12 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