note 77869 added to control-structures.foreach
| From: | pavel at krcil dot cz | Date: | Mon, 17 Sep 2007 12:41:05 +0000 |
| Subject: | note 77869 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130548@lists.php.net to get a copy of this message | ||
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!
----
Server IP: 147.32.160.17
Probable Submitter: 213.151.83.254
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/77869
Del: integrated -- https://master.php.net/note/delete/77869/integrated
Del: useless -- https://master.php.net/note/delete/77869/useless
Del: bad code -- https://master.php.net/note/delete/77869/bad+code
Del: spam -- https://master.php.net/note/delete/77869/spam
Del: non-english -- https://master.php.net/note/delete/77869/non-english
Del: in docs -- https://master.php.net/note/delete/77869/in+docs
Del: other reasons-- https://master.php.net/note/delete/77869
Reject -- https://master.php.net/note/reject/77869
Search -- https://master.php.net/manage/user-notes.php