#30496 [Com]: foreach wrong assignment with multidim arrays

From: Date: Wed, 20 Oct 2004 15:58:39 +0000
Subject: #30496 [Com]: foreach wrong assignment with multidim arrays
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-67837@lists.php.net to get a copy of this message
 ID:               30496
 Comment by:       mserra at consrav dot net
 Reported By:      esartoni at omniaglobal dot net
 Status:           Bogus
 Bug Type:         Arrays related
 Operating System: Linux
 PHP Version:      4CVS-2004-10-20 (stable)
 New Comment:

$a=array(1,2,3,4,5);
foreach($a as $value) {
  echo $value."\n";
}

OUTPUT:
Array
Array
Array
Array
Array

EXPECTED:
1
2
3
4
5


Previous Comments:
------------------------------------------------------------------------

[2004-10-20 16:00:17] esartoni at omniaglobal dot net

I'm sorry derick but here with v4.3.10-dev doesn't work!

I've also tried with Solaris (SPARC) with same results.

------------------------------------------------------------------------

[2004-10-20 15:34:28] derick@php.net

Works fine here.

------------------------------------------------------------------------

[2004-10-20 15:19:33] esartoni at omniaglobal dot net

With PHP v4.3.9 works ok!

------------------------------------------------------------------------

[2004-10-20 15:17:40] esartoni at omniaglobal dot net

Description:
------------
foreach doesn't work as expected when using multidimensional arrays.

Reproduce code:
---------------
<?php
	$a=array();
	$a[]=array("one", "two", "three");
	$a[]=array("five", "six", "seven");
	
	// Code 1 (THIS DON'T WORK AS EXPECTED)
	foreach ($a as $value) {
		echo join(",", $value)."\n";
	}
/*
  This code below is a workaround:

        // Code 2 (THIS WORKS!)
	foreach ($a as $key => $value) {
		echo join(",", $value)."\n";
	}
*/
?>

Expected result:
----------------
one,two,three
five,six,seven

Actual result:
--------------
Array,0
Array,1


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=30496&edit=1


Thread (9 messages)

« previous php.bugs (#67837) next »