Zwiter Posted July 17, 2008 Share Posted July 17, 2008 Hello all More than explanation, here is the code : <?php print_r($columns); print_r($titles); foreach($columns as $key => $value) { print_r($titles); die; [other instructions] }?> And here is extract of each print_r: print_r($columns): Array ( [project_cmts] => Array ( [title] => Project comments [excel] => Project comments ) [...] ) first print_r($titles): Array ( [...] [Comments] => //empty string [...] ) fsecond print_r($titles): Array ( [...] [Comments] => Array ( [title] => Project comments [excel] => Project comments ) [...] ) As you can see, the content of $titles was changed, but how? Thank you! Z. Link to comment https://forums.phpfreaks.com/topic/115280-solved-array-modified-without-modifing-instruction-oo/ Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 Well, excluding code makes it pretty much impossible to debug. [other instructions] <- probably your issue Link to comment https://forums.phpfreaks.com/topic/115280-solved-array-modified-without-modifing-instruction-oo/#findComment-592670 Share on other sites More sharing options...
Zwiter Posted July 17, 2008 Author Share Posted July 17, 2008 i have a die instruction. how come the next instructions may help? Anyway, here they are : <?php print_r($columns); print_r($titles); foreach($columns as $key => $value) { print_r($titles); die; if (array_key_exists($value['excel'], $titles)) $titles[$value['excel']] = $key; else $titles[$value['excel']] = false; } ?> But the problem is still the same with this code: <?php print_r($columns); print_r($titles); foreach($columns as $key => $value) { print_r($titles); die; } ?> Link to comment https://forums.phpfreaks.com/topic/115280-solved-array-modified-without-modifing-instruction-oo/#findComment-592683 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 Dur, die ends the execution of the script. I have no idea why you have it in a loop without any clauses. Link to comment https://forums.phpfreaks.com/topic/115280-solved-array-modified-without-modifing-instruction-oo/#findComment-592699 Share on other sites More sharing options...
Zwiter Posted July 17, 2008 Author Share Posted July 17, 2008 I have found the problem. I found that the only way left after i have delete all instuctions inside my foreach is reference. So i trac all the reference in my page ( I use some to modify data, especialy array content). And i found it : // ok $titles = array_flip($titles); foreach ($titles as $key => $value) $titles[$key] = NULL; // no ok $titles = array_flip($titles); foreach ($titles as &$value) $value = NULL; I am programming in perl and php at same time. (php for the user interface, and perl to run scripts on data (DNA stuff)) So variables which are local in perl, and disapear after the end of the block code are not deleted in php. So the reference stayed and annoyed me. thank you for your help. Z. Link to comment https://forums.phpfreaks.com/topic/115280-solved-array-modified-without-modifing-instruction-oo/#findComment-592705 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.