<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>foreach | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/foreach/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Sat, 24 Sep 2011 08:57:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>PHP odds! today: pass by reference traps</title>
		<link>https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/</link>
					<comments>https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/#comments</comments>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Thu, 25 Aug 2011 09:42:59 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[reference]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=1590</guid>

					<description><![CDATA[<p>This is dangerous: This works, but now the $value var is in the array by reference which can lateron lead to: Notice: Array to string conversion EDIT: see below in the comments for when&#8230; This works better: Using reference, array_walk und lambda functions works: or that (thanks lars):</p>
The post <a href="https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/">PHP odds! today: pass by reference traps</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>This is dangerous:</p>
<pre class="brush: php; title: ; notranslate">
//example array
$array = array('a' =&gt; array(array(243,453,435,232)));

foreach ($array&#x5B;'a'] as &amp;$value) {
         $value&#x5B;3] = $newvalue;
}
</pre>
<p>This works, but now the $value var is in the array by reference which can lateron lead to:<br />
<strong>Notice: Array to string conversion</strong><br />
EDIT:<br />
see below in the comments for when&#8230;</p>
<p>This works better:</p>
<p><span id="more-1590"></span></p>
<p>Using reference, array_walk und lambda functions works:</p>
<pre class="brush: php; title: ; notranslate">
array_walk($array&#x5B;$key], function(&amp;$value, $key, $newvalue) {
                                   $value&#x5B;3] = $newvalue;
                          },$newvalue);
//works
</pre>
<p>or that (thanks lars):</p>
<pre class="brush: php; title: ; notranslate">
foreach ($array&#x5B;'a'] as $k =&gt; $value) {
         $array&#x5B;'a']&#x5B;$k]&#x5B;3] = $newvalue;
}
</pre>The post <a href="https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/">PHP odds! today: pass by reference traps</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
					<wfw:commentRss>https://nerdpress.org/2011/08/25/php-odds-today-pass-by-reference-traps/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
