&reftitle.examples;
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.
For Each in ASP
"
Next
%>
]]>
while() ... Next() in PHP 4
Next()) {
echo $obj->Name . " ";
}
?>
]]>
foreach in PHP 5
Name . " ";
}
?>
]]>
Arrays and Array-style COM properties
Many COM objects expose their properties as arrays, or using array-style
access. In PHP 4, you may use PHP array syntax to read/write such a
property, but only a single dimension is allowed. If you want to read a
multi-dimensional property, you could instead make the property access
into a function call, with each parameter representing each dimension of
the array access, but there is no way to write to such a property.
PHP 5 introduces the following new features to make your life easier:
Access multi-dimensional arrays, or COM properties that require
multiple parameters using PHP array syntax. You can also write or set
properties using this technique.
Iterate SafeArrays ("true" arrays) using the control structure. This works
because SafeArrays include information about their size. If an
array-style property implements IEnumVariant then you can also use
foreach for that property too; take a look at for more information on this topic.