tag:blogger.com,1999:blog-5023448542823447711.post495156489292765571..comments2023-09-22T04:05:16.253-07:00Comments on Optimizely Module: Notes on Converting to Drupal 8: PHP reference in foreach loop -- gotcha!Earl Fonghttp://www.blogger.com/profile/05682372868411855409noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5023448542823447711.post-37303748585686015012015-03-08T20:22:34.283-07:002015-03-08T20:22:34.283-07:00The article on foreach at the url you provided sho...The article on foreach at the url you provided shows how there are a lot of complications that can arise when using references in conjunction with this looping construct.<br /><br />The particular comment by Delian Krustev proved extremely helpful. It explains how at the end of the first loop, the variable remains a reference to the last array element. In the second loop, the variable continues to refer only to the _last_ element. So as the second loop executes, array values are in turn assigned to the last element, with the final result that the last element ends up having the value of the next-to-last element. <br /><br />That was exactly the understanding I was hoping to get. Thanks!!<br />Earl Fonghttps://www.blogger.com/profile/05682372868411855409noreply@blogger.comtag:blogger.com,1999:blog-5023448542823447711.post-19356939971723649952015-03-08T19:47:22.346-07:002015-03-08T19:47:22.346-07:00Do a search for "PHP foreach internal array p...Do a search for "PHP foreach internal array pointer". And / or "internal array pointer" http://php.net/manual/en/control-structures.foreach.php.<br /><br />Not sure if this is related but perhaps of value?Anonymousnoreply@blogger.com