<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: PHP odds! today: pass by reference traps	</title>
	<atom:link href="https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Sat, 24 Sep 2011 08:57:33 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: Lars		</title>
		<link>https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/#comment-174</link>

		<dc:creator><![CDATA[Lars]]></dc:creator>
		<pubDate>Fri, 26 Aug 2011 13:37:53 +0000</pubDate>
		<guid isPermaLink="false">https://nerdpress.org/?p=1590#comment-174</guid>

					<description><![CDATA[Ach, jetzt versteh ich auch, was dein Problem ist!

Ja, die Variablen-Referenz bleibt auch bei reference nach der foreach bestehen, siehe entsprechende Warnung im PHP Manual: http://php.net/manual/en/control-structures.foreach.php

Also einfach ein unset() zwischen die zwei foreach schieben und gut.]]></description>
			<content:encoded><![CDATA[<p>Ach, jetzt versteh ich auch, was dein Problem ist!</p>
<p>Ja, die Variablen-Referenz bleibt auch bei reference nach der foreach bestehen, siehe entsprechende Warnung im PHP Manual: <a href="http://php.net/manual/en/control-structures.foreach.php" rel="nofollow ugc">http://php.net/manual/en/control-structures.foreach.php</a></p>
<p>Also einfach ein unset() zwischen die zwei foreach schieben und gut.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Max Girkens		</title>
		<link>https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/#comment-173</link>

		<dc:creator><![CDATA[Max Girkens]]></dc:creator>
		<pubDate>Fri, 26 Aug 2011 11:06:03 +0000</pubDate>
		<guid isPermaLink="false">https://nerdpress.org/?p=1590#comment-173</guid>

					<description><![CDATA[wusste gar nicht dass das geht mit der Referenz in der foreach Schleife. Seit welcher Version gibt&#039;s das denn?

Die Merkwürdigkeit scheint aber auch schon &lt;a href=&quot;http://www.v13.gr/blog/?p=15&quot; rel=&quot;nofollow&quot;&gt;anderen&lt;/a&gt; passiert zu sein...]]></description>
			<content:encoded><![CDATA[<p>wusste gar nicht dass das geht mit der Referenz in der foreach Schleife. Seit welcher Version gibt&#8217;s das denn?</p>
<p>Die Merkwürdigkeit scheint aber auch schon <a href="http://www.v13.gr/blog/?p=15" rel="nofollow">anderen</a> passiert zu sein&#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ivo Bathke		</title>
		<link>https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/#comment-172</link>

		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Thu, 25 Aug 2011 11:33:09 +0000</pubDate>
		<guid isPermaLink="false">https://nerdpress.org/?p=1590#comment-172</guid>

					<description><![CDATA[yep youre right
the code was incomplete

the problem was actually this:
[code lang=&quot;php&quot;]
$array = array(&#039;a&#039; =&#062; array(array(243,453,435,232)));
 
foreach ($array[&#039;a&#039;] as &#038;$value) {
         $value[3] = &#039;aa&#039;;
}
var_dump($array);

foreach ($array as $value) {
    var_dump($value);
      foreach ($value as $e) {
          var_dump($e);
           echo implode(&#039;,&#039;, $e);
     }
}
[/code]

the problem here is that the second $value is due to the &quot;reference&quot; in the first loop somehow &quot;occupied&quot; with the reference and not newly set, as i thought

so this works:

[code lang=&quot;php&quot;]
$array = array(&#039;a&#039; =&#062; array(array(243,453,435,232)));
 
foreach ($array[&#039;a&#039;] as &#038;$value) {
         $value[3] = &#039;aa&#039;;
}
var_dump($array);

foreach ($array as $v) {
    var_dump($v);
      foreach ($v as $e) {
          var_dump($e);
           echo implode(&#039;,&#039;, $e);
     }
}
[/code]

all this trouble because of my lazyness to write some chars more
the longer way works of course, as you proposed:
[code php=&quot;lang&quot;]
foreach ($array[&#039;a&#039;] as $k =&#062; $value) {
         $array[&#039;a&#039;][$k][3] = $newvalue;
}
[/code]

Lunchbreak!]]></description>
			<content:encoded><![CDATA[<p>yep youre right<br />
the code was incomplete</p>
<p>the problem was actually this:</p>
<pre class="brush: php; title: ; notranslate">
$array = array('a' =&gt; array(array(243,453,435,232)));
 
foreach ($array&#x5B;'a'] as &amp;$value) {
         $value&#x5B;3] = 'aa';
}
var_dump($array);

foreach ($array as $value) {
    var_dump($value);
      foreach ($value as $e) {
          var_dump($e);
           echo implode(',', $e);
     }
}
</pre>
<p>the problem here is that the second $value is due to the &#8220;reference&#8221; in the first loop somehow &#8220;occupied&#8221; with the reference and not newly set, as i thought</p>
<p>so this works:</p>
<pre class="brush: php; title: ; notranslate">
$array = array('a' =&gt; array(array(243,453,435,232)));
 
foreach ($array&#x5B;'a'] as &amp;$value) {
         $value&#x5B;3] = 'aa';
}
var_dump($array);

foreach ($array as $v) {
    var_dump($v);
      foreach ($v as $e) {
          var_dump($e);
           echo implode(',', $e);
     }
}
</pre>
<p>all this trouble because of my lazyness to write some chars more<br />
the longer way works of course, as you proposed:</p>
<pre class="brush: plain; title: ; notranslate">
foreach ($array&#x5B;'a'] as $k =&gt; $value) {
         $array&#x5B;'a']&#x5B;$k]&#x5B;3] = $newvalue;
}
</pre>
<p>Lunchbreak!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Lars		</title>
		<link>https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/#comment-171</link>

		<dc:creator><![CDATA[Lars]]></dc:creator>
		<pubDate>Thu, 25 Aug 2011 09:57:26 +0000</pubDate>
		<guid isPermaLink="false">https://nerdpress.org/?p=1590#comment-171</guid>

					<description><![CDATA[The first code sample doesn&#039;t make any sense. $value[4] while $value is 0?! You either mean $array[$key][4] = $newvalue; or foreach ($array as $k =&#062; &#038;$v)...]]></description>
			<content:encoded><![CDATA[<p>The first code sample doesn&#8217;t make any sense. $value[4] while $value is 0?! You either mean $array[$key][4] = $newvalue; or foreach ($array as $k =&gt; &amp;$v)&#8230;</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
