php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #22278 Improvement of foreach function(?)
Submitted: 2003-02-18 11:37 UTC Modified: 2003-02-18 11:47 UTC
From: mazanek at abeo dot cz Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.2.3 OS: windows
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 - 20 = ?
Subscribe to this entry?

 
 [2003-02-18 11:37 UTC] mazanek at abeo dot cz
this is old issue #3074 - do you support foreach by reference?

I'm using PHP Version 4.2.2.
Having multidimensional array - $multi_array.
I would like to change the $multi_array from place marked **HERE**

foreach($multi_array AS $multi_key=>$multi_array_item)
{	foreach($multi_array_item["another_array"] AS $key=>$value)
	{	if($value=="asdfg")
		{	**HERE**
		}
		...
	}
}

I have to do it using:
$multi_array[$multi_key]["another_array"][$key]=$new_value

- - - - - - - - 

It would be nice to use "&" to change the $multi_array:

foreach($multi_array AS $multi_key=>&$multi_array_item)
{	foreach($multi_array_item["another_array"] AS &$value)
	{	if($value=="asdfg")
		{	$value=$new_value;
			$multi_array_item["value_have_changed"]=true;
		}else
		{	$multi_array_item["value_have_changed"]=false;
		}
		...
	}
}


Is it possible to implement this to new version of PHP?

Thanks,

Jan Maz?nek
mazanek@abeo.cz

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-18 11:47 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

bug #15663
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 13:01:33 2025 UTC