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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC