<?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>chimanaco blog &#187; PHP</title>
	<atom:link href="http://blog.chimanaco.net/archives/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.chimanaco.net</link>
	<description>Flash, ActionScript, JavaScript, something like that</description>
	<lastBuildDate>Sat, 21 Jan 2012 05:05:59 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>配列の重複を削除する</title>
		<link>http://blog.chimanaco.net/archives/20100723181647.php</link>
		<comments>http://blog.chimanaco.net/archives/20100723181647.php#comments</comments>
		<pubDate>Fri, 23 Jul 2010 09:16:47 +0000</pubDate>
		<dc:creator>chimanaco</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.chimanaco.net/?p=617</guid>
		<description><![CDATA[配列に同じ値が入る可能性があって、重複分は削除したいとき。
array_unique という関数があるんだけど、これは連想配列には使えないようです。削除したキーの分も自動的に詰めてくれる訳ではない。

&#60;?php
 [...]]]></description>
			<content:encoded><![CDATA[<p>配列に同じ値が入る可能性があって、重複分は削除したいとき。<br />
<a href="http://jp.php.net/manual/ja/function.array-unique.php">array_unique</a> という関数があるんだけど、これは連想配列には使えないようです。削除したキーの分も自動的に詰めてくれる訳ではない。</p>
<pre>
&lt;?php
	$input = array(3, 5, 6, 6, 3, 8);
	$result = array_unique($input);
	print_r($result);
?&gt;
</pre>
<p>とやると、キーはそのまま。</p>
<pre>
Array ( [0] => 3 [1] => 5 [2] => 6 [5] => 8 )
</pre>
<p>できれば [0] から詰めたものを使いたいので調べていると、このような記述でいけるようです。</p>
<pre>
&lt;?php
	$data = array(
	array(&quot;name&quot; =&gt; &quot;ルナティック雑技団&quot;, &quot;price&quot; =&gt; &quot;410&quot;),
	array(&quot;name&quot; =&gt; &quot;詐欺とペテンの大百科&quot;, &quot;price&quot; =&gt; &quot;5040&quot;),
	array(&quot;name&quot; =&gt; &quot;ルナティック雑技団&quot;, &quot;price&quot; =&gt; &quot;410&quot;),
	array(&quot;name&quot; =&gt; &quot;スティーブ・ジョブズ 驚異のプレゼン&quot;, &quot;price&quot; =&gt; &quot;1890&quot;)
	);

	// 検証用配列
	$tmp = array();
	foreach($data as $key =&gt; $val){
	// 検証用配列に値が見つからなければ$tmpに格納
		if(!in_array($val,$tmp)){
			$tmp[] = $val;
		}
	}
	$data = $tmp;

	print_r($data);
?&gt;
</pre>
<p>以下のように [0] から詰めた配列ができます。</p>
<pre>
Array ( [0] => Array ( [name] => ルナティック雑技団 [price] => 410 ) [1] => Array ( [name] => 詐欺とペテンの大百科 [price] => 5040 ) [2] => Array ( [name] => スティーブ・ジョブズ 驚異のプレゼン [price] => 1890 ) )
</pre>
<p>参考</p>
<ul>
<li><a href="http://okwave.jp/qa/q4095139.html">多次元配列の重複削除 | OKWave</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.chimanaco.net/archives/20100723181647.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

