downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Arrays y propiedades estilo array de COM> <Ejemplos
[edit] Last updated: Wed, 19 Jun 2013

view this page in

For Each

Desde PHP 5 se puede usar la sentencia foreach propia de PHP para iterar sobre el contenido de un COM/OLE IEnumVariant estándar. En términos entendibles, esto significa que se puede usar foreach en lugares donde se podría usar For Each en código VB/ASP.

Ejemplo #1 For Each en ASP

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

Ejemplo #2 while() ... Next() en PHP 4

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

?>

Ejemplo #3 foreach en PHP 5

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

?>



add a note add a note User Contributed Notes For Each - [1 notes]
up
1
szir at sch dot bme dot hu
1 year 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)

 
show source | credits | sitemap | contact | advertising | mirror sites