<?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>相同元素 &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/%E7%9B%B8%E5%90%8C%E5%85%83%E7%B4%A0/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Mon, 01 Oct 2012 09:54:26 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.1</generator>
	<item>
		<title>二维数组过滤相同元素 并计算和值函数</title>
		<link>https://www.mudbest.com/%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e8%bf%87%e6%bb%a4%e7%9b%b8%e5%90%8c%e5%85%83%e7%b4%a0-%e5%b9%b6%e8%ae%a1%e7%ae%97%e5%92%8c%e5%80%bc%e5%87%bd%e6%95%b0/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Mon, 18 Jul 2011 14:03:48 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[相同元素]]></category>
		<category><![CDATA[过滤]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=715</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[<pre class="brush: php; title: ; notranslate">
&lt;?php
$array = array (
		Array (&quot;goods_id&quot; =&gt; &quot;001&quot;, &quot;goods_num&quot; =&gt; 5 ), 
		Array (&quot;goods_id&quot; =&gt; &quot;002&quot;, &quot;goods_num&quot; =&gt; 10 ), 
		Array (&quot;goods_id&quot; =&gt; &quot;003&quot;, &quot;goods_num&quot; =&gt; 3 ), 
		Array (&quot;goods_id&quot; =&gt; &quot;002&quot;, &quot;goods_num&quot; =&gt; 4 ) 
		);

/**
 * 二维数组过滤相同元素 并计算和值
 * 2011-07-18
 */
function array_2d_count_key($_2dArray, $key, $key2) {
	$nArray = array ();
	foreach ( $_2dArray as $k ) {
		$ckey = $k &#x5B;$key];
		$cVal = $k &#x5B;$key2];
		$cArray = array ($ckey =&gt; $cVal );
		if (array_key_exists ( $ckey, $nArray )) {
			$nArray &#x5B;$ckey] = $cVal + $nArray &#x5B;$ckey];
		} else {
			$nArray &#x5B;$ckey] = $cVal;
		}
	}
	return $nArray;
}

print_r ( array_2d_count_key ( $array, 'goods_id', 'goods_num' ) );
?&gt;
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
