note 75182 added to ref.array

From: Date: Wed, 16 May 2007 21:05:32 +0000
Subject: note 75182 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-126650@lists.php.net to get a copy of this message
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'] ---- Server IP: 194.145.210.4 Probable Submitter: 81.1.124.167 ---- Manual Page -- http://www.php.net/manual/en/ref.array.php Edit -- https://master.php.net/note/edit/75182 Del: integrated -- https://master.php.net/note/delete/75182/integrated Del: useless -- https://master.php.net/note/delete/75182/useless Del: bad code -- https://master.php.net/note/delete/75182/bad+code Del: spam -- https://master.php.net/note/delete/75182/spam Del: non-english -- https://master.php.net/note/delete/75182/non-english Del: in docs -- https://master.php.net/note/delete/75182/in+docs Del: other reasons-- https://master.php.net/note/delete/75182 Reject -- https://master.php.net/note/reject/75182 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#126650) next »