note 77869 rejected from control-structures.foreach by bjori

From: Date: Mon, 17 Sep 2007 12:55:05 +0000
Subject: note 77869 rejected from control-structures.foreach by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-130549@lists.php.net to get a copy of this message
Note Submitter: pavel at krcil dot cz ---- Hello, i have problem with foreach when i call array by function. Two uses two difference results. example: <?php class Foo { function GetSomething() { return array ( array ( 1, 2, 3 ), array ( 4, 5, 6 ) ); } function ListSomething() { // right result $Text = ''; foreach $this -> GetSomething() as $Value ) $Text .= $Value [ 0 ]; } } //not working $Text= ''; $Foo = new Foo(); // This construction return only first value PHP Version 5.1.2 foreach ($Foo->GetSomething() as $Value) $text .= $Value[0]; // I must use this construction and then everything ok .. foreach (array_values($Foo->GetSomething()) as $Value) $text .= $Value[0]; ?> Do you anybody know, wheres problem? Thanks!

« previous php.notes (#130549) next »