note 75182 deleted from ref.array by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: djspy187 at gmail dot com 

----

I had an issue with arrays and copying them by reference as follows.

	// Loop on the list and insert default values
	foreach ($navigation as &$item)
	{		
		$children = &$item['children']};

		foreach ($children as &$child)
		{
		 // Do stuff
		}
	}

This would give me error message 

Fatal error: Cannot create references to/from string offsets nor overloaded objects in /var/www/dev/kh_system/navigation.php on line 103

Even though $item['children'] is an array.

The workaround is to do a for ($i =0;$i < count($Item);$i++) and to then access the children like this

$navigation[$i]['children']
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.