<?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>Life &#187; php</title>
	<atom:link href="http://life.co-hey.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://life.co-hey.com</link>
	<description></description>
	<lastBuildDate>Tue, 17 Jan 2012 08:15:38 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>phpの連想配列から指定したキーの要素を、指定したキーの順番で取得する方法</title>
		<link>http://life.co-hey.com/2011/04/php%e3%81%ae%e9%80%a3%e6%83%b3%e9%85%8d%e5%88%97%e3%81%8b%e3%82%89%e6%8c%87%e5%ae%9a%e3%81%97%e3%81%9f%e3%82%ad%e3%83%bc%e3%81%ae%e8%a6%81%e7%b4%a0%e3%82%92%e3%80%81%e6%8c%87%e5%ae%9a%e3%81%97/</link>
		<comments>http://life.co-hey.com/2011/04/php%e3%81%ae%e9%80%a3%e6%83%b3%e9%85%8d%e5%88%97%e3%81%8b%e3%82%89%e6%8c%87%e5%ae%9a%e3%81%97%e3%81%9f%e3%82%ad%e3%83%bc%e3%81%ae%e8%a6%81%e7%b4%a0%e3%82%92%e3%80%81%e6%8c%87%e5%ae%9a%e3%81%97/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 07:24:46 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[web & pc]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=968</guid>
		<description><![CDATA[日本語で説明すると面倒ですねｗ 以下のような配列から 1 2 3 4 5 6 $list = array&#40; &#34;item100&#34; =&#62; &#34;aaa&#34;, &#34;ite [...]]]></description>
			<content:encoded><![CDATA[<p>
日本語で説明すると面倒ですねｗ<br />
<br />
以下のような配列から<br />
<br />

<div class="wp_codebox"><table><tr id="p9684"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p968code4"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #000088;">$list</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;item100&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;aaa&quot;</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">&quot;item50&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;bbb&quot;</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">&quot;item30&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ccc&quot;</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">&quot;item10&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ddd&quot;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
以下のような配列を取得したかったのです。<br />
<br />

<div class="wp_codebox"><table><tr id="p9685"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p968code5"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #000088;">$list</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;item30&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ccc&quot;</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">&quot;item50&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;bbb&quot;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
<br />
最終的にたどり着いたのは、この方法でした。<br />
<br />

<div class="wp_codebox"><table><tr id="p9686"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p968code6"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #000088;">$list</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;item100&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;aaa&quot;</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">&quot;item50&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;bbb&quot;</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">&quot;item30&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ccc&quot;</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">&quot;item10&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;ddd&quot;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cols</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;item30&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;item50&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span>
    <span style="color: #990000;">array_flip</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cols</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
    <span style="color: #990000;">array_intersect_key</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$list</span><span style="color: #339933;">,</span> <span style="color: #990000;">array_flip</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cols</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
<br />
array_intersect_keyを行うと必要な要素は取得できるんですが、要素の並び順がもともとの $list の状態を保持していました。そこで、array_mergeを使って、指定したkeyの順番を保ちつつ、値を $list のもので上書きしています。</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20php%E3%81%AE%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%81%8B%E3%82%89%E6%8C%87%E5%AE%9A%E3%81%97%E3%81%9F%E3%82%AD%E3%83%BC%E3%81%AE%E8%A6%81%E7%B4%A0%E3%82%92%E3%80%81%E6%8C%87%E5%AE%9A%E3%81%97%E3%81%9F%E3%82%AD%E3%83%BC%E3%81%AE%E9%A0%86%E7%95%AA%E3%81%A7%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95%20-%20Life%20http%3A%2F%2Flife.co-hey.com%2F2011%2F04%2Fphp%25e3%2581%25ae%25e9%2580%25a3%25e6%2583%25b3%25e9%2585%258d%25e5%2588%2597%25e3%2581%258b%25e3%2582%2589%25e6%258c%2587%25e5%25ae%259a%25e3%2581%2597%25e3%2581%259f%25e3%2582%25ad%25e3%2583%25bc%25e3%2581%25ae%25e8%25a6%2581%25e7%25b4%25a0%25e3%2582%2592%25e3%2580%2581%25e6%258c%2587%25e5%25ae%259a%25e3%2581%2597%2F&amp;in_reply_to_status_id=59880031509430272" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2011/04/php%e3%81%ae%e9%80%a3%e6%83%b3%e9%85%8d%e5%88%97%e3%81%8b%e3%82%89%e6%8c%87%e5%ae%9a%e3%81%97%e3%81%9f%e3%82%ad%e3%83%bc%e3%81%ae%e8%a6%81%e7%b4%a0%e3%82%92%e3%80%81%e6%8c%87%e5%ae%9a%e3%81%97/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>trigger_errorの使い方</title>
		<link>http://life.co-hey.com/2011/02/trigger_error%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9/</link>
		<comments>http://life.co-hey.com/2011/02/trigger_error%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9/#comments</comments>
		<pubDate>Mon, 07 Feb 2011 03:23:34 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[web & pc]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=957</guid>
		<description><![CDATA[使い方マニュアルはこちら。 http://phpspot.net/php/man/php/function.trigger-error.html 私は読んでもピンとこなかったので、動かしてみることに。 trigger_e [...]]]></description>
			<content:encoded><![CDATA[<p>
使い方マニュアルはこちら。<br />
<a href="http://phpspot.net/php/man/php/function.trigger-error.html">http://phpspot.net/php/man/php/function.trigger-error.html</a><br />
<br />
私は読んでもピンとこなかったので、動かしてみることに。<br />
trigger_errorに渡したメッセージが、ブラウザに出力されました。表示形式はphpのエラーと同じフォーマットで、trigger_errorを実行したファイル、ファイルの行数、設定したメッセージが表示されます。<br />
（&#8221;}&#8221;の対応が間違ってたりしたときに、warningとかでるあのフォーマットです。)<br />
<br />
自分で共通クラスとかつくったときに、使い方が間違っていたら今までException発生させて間違っているよということを通知していましたが、trigger_errorを使った方がいいかなと思いました。<br />
Exceptionの中身からエラー発生行数とか見つけなくていいですし。<br />
</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20trigger_error%E3%81%AE%E4%BD%BF%E3%81%84%E6%96%B9%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F3dddrqm&amp;in_reply_to_status_id=34452203611627520" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2011/02/trigger_error%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZendFramework1.11.1はPCREのUnicode対応が必要</title>
		<link>http://life.co-hey.com/2011/02/zendframework1-11-1%e3%81%afpcre%e3%81%aeunicode%e5%af%be%e5%bf%9c%e3%81%8c%e5%bf%85%e8%a6%81/</link>
		<comments>http://life.co-hey.com/2011/02/zendframework1-11-1%e3%81%afpcre%e3%81%aeunicode%e5%af%be%e5%bf%9c%e3%81%8c%e5%bf%85%e8%a6%81/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 04:53:41 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[web & pc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=937</guid>
		<description><![CDATA[ZendFramework1.10.1から、1.11.1に変えたときに、Noticeメッセージがでました。内容は、「PCREがUnicodeをサポートしてませんよ」というもの。 Niticeメッセージはでないようにしてた [...]]]></description>
			<content:encoded><![CDATA[<p>
ZendFramework1.10.1から、1.11.1に変えたときに、Noticeメッセージがでました。内容は、「PCREがUnicodeをサポートしてませんよ」というもの。<br />
Niticeメッセージはでないようにしてたのにと思って調べてみたら、ZendFrameworkのZend_Locale内で、trigger_errorを使ってメッセージを出してました。なので、ちゃんとPCREをUnicode対応にしました。<br />
<br />
参考にさせていただいたサイトは以下です。<br />
<a href="http://junrei.dip.jp/wordpress/nagios/pnp4nagios%EF%BC%880-6-2%EF%BC%89%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB/">http://junrei.dip.jp/wordpress/nagios/pnp4nagios%EF%BC%880-6-2%EF%BC%89%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB/</a><br />
<br />
以下のコマンドで、PCREがUnicodeに対応してないことを確認。<br />
<br />

<div class="wp_codebox"><table><tr id="p93711"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p937code11"><pre class="sh" style="font-family:Osaka-mono,monospace;"># pcretest -C
PCRE version 8.02 2010-03-19
Compiled with
  UTF-8 support
  No Unicode properties support
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack</pre></td></tr></table></div>

<br />
<br />
<br />
まずは、以下のファイルを作成。<br />
デフォルトのリポジトリに、pcre-unicodeがないので、下記のリポジトリを追加します。私の環境だと、phpをインストールするときに、追加してました。（忘れてました。。）<br />
<br />

<div class="wp_codebox"><table><tr id="p93712"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p937code12"><pre class="sh" style="font-family:Osaka-mono,monospace;"># vi /etc/yum.repos.d/utterramblings.repo
&nbsp;
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka</pre></td></tr></table></div>

<br />
<br />
<br />
そして、以下のコマンドを実行<br />
<br />

<div class="wp_codebox"><table><tr id="p93713"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p937code13"><pre class="sh" style="font-family:Osaka-mono,monospace;"># yum install pcre-unicode</pre></td></tr></table></div>

<br />
<br />
<br />
再度、unicodeに対応しているかをコマンドで確認。<br />
<br />

<div class="wp_codebox"><table><tr id="p93714"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p937code14"><pre class="sh" style="font-family:Osaka-mono,monospace;"># pcretest -C
PCRE version 8.02 2010-03-19
Compiled with
  UTF-8 support
  Unicode properties support
  Newline sequence is LF
  \R matches all Unicode newlines
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack</pre></td></tr></table></div>

<br />
<br />
Unicode properties supportになったのでOK。<br />
Noticeメッセージもでなくなりました。<br />
ZendFrameworkを利用するときに覚えておく必要がありそうです。</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20ZendFramework1.11.1%E3%81%AFPCRE%E3%81%AEUnicode%E5%AF%BE%E5%BF%9C%E3%81%8C%E5%BF%85%E8%A6%81%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F4g4f9qu&amp;in_reply_to_status_id=32662932630282240" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2011/02/zendframework1-11-1%e3%81%afpcre%e3%81%aeunicode%e5%af%be%e5%bf%9c%e3%81%8c%e5%bf%85%e8%a6%81/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZendFrameworkの環境変数APPLICATION_ENVを設定する</title>
		<link>http://life.co-hey.com/2011/02/zendframework%e3%81%ae%e7%92%b0%e5%a2%83%e5%a4%89%e6%95%b0application_env%e3%82%92%e8%a8%ad%e5%ae%9a%e3%81%99%e3%82%8b/</link>
		<comments>http://life.co-hey.com/2011/02/zendframework%e3%81%ae%e7%92%b0%e5%a2%83%e5%a4%89%e6%95%b0application_env%e3%82%92%e8%a8%ad%e5%ae%9a%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Tue, 01 Feb 2011 01:36:50 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[web & pc]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=945</guid>
		<description><![CDATA[ZendFrameworkでは、index.phpにもともと書いてある記述に以下の環境変数に関わるものがあります。 1 2 3 / Define application environment defined&#40;' [...]]]></description>
			<content:encoded><![CDATA[<p>
ZendFrameworkでは、index.phpにもともと書いてある記述に以下の環境変数に関わるものがあります。<br />
<br />

<div class="wp_codebox"><table><tr id="p94518"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p945code18"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #339933;">/</span> <span style="color: #990000;">Define</span> application environment
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">||</span> <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'production'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
<br />
APPLICATION_ENVが設定されてなかったら、&#8217;production&#8217; という文字列を、APPLICATION_ENVとして設定するという内容です。このAPPLICATION_ENVはどこで使われているかというと、Bootstrap内で、application.iniを読み込む際に、パラメタとして渡されています。<br />
<br />
application.iniは、DB接続設定等を書くファイルで、APPLICATION_ENVの値を、本番環境、テスト環境等で変えることによって、ファイルを編集することなく、DB接続先の設定を環境に合ったものに設定することができます。iniファイルの書き方は、こちらをご参照ください(<a href="http://framework.zend.com/manual/1.11/ja/zend.config.adapters.ini.html">http://framework.zend.com/manual/1.11/ja/zend.config.adapters.ini.html</a>)<br />
<br />
今回、<strong>/etc/sysconfig/httpd</strong> に以下の記述を追加すると、apacheにて環境変数を追加することができました。<br />
<br />

<div class="wp_codebox"><table><tr id="p94519"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p945code19"><pre class="sh" style="font-family:Osaka-mono,monospace;">export APPLICATION_ENV=&quot;development&quot;</pre></td></tr></table></div>

<br />
<br />
.htaccessを使うと、&#8221;setEnv&#8221;を使って記述することもできます。その場合の書き方は以下になります。<br />
<br />

<div class="wp_codebox"><table><tr id="p94520"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p945code20"><pre class="htaccess" style="font-family:Osaka-mono,monospace;">setEnv APPLICATION_ENV development</pre></td></tr></table></div>

<br />
<br />
これまで、.htaccessを使ったやり方のみでやってきて、/etc/sysconfig/httpd を編集する方法を知りませんでした。</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20ZendFramework%E3%81%AE%E7%92%B0%E5%A2%83%E5%A4%89%E6%95%B0APPLICATION_ENV%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F4jgqbza&amp;in_reply_to_status_id=32251003998834688" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2011/02/zendframework%e3%81%ae%e7%92%b0%e5%a2%83%e5%a4%89%e6%95%b0application_env%e3%82%92%e8%a8%ad%e5%ae%9a%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Mailで文字化けしなくなっていた</title>
		<link>http://life.co-hey.com/2011/01/zend_mail%e3%81%a7%e6%96%87%e5%ad%97%e5%8c%96%e3%81%91%e3%81%97%e3%81%aa%e3%81%8f%e3%81%aa%e3%81%a3%e3%81%a6%e3%81%84%e3%81%9f/</link>
		<comments>http://life.co-hey.com/2011/01/zend_mail%e3%81%a7%e6%96%87%e5%ad%97%e5%8c%96%e3%81%91%e3%81%97%e3%81%aa%e3%81%8f%e3%81%aa%e3%81%a3%e3%81%a6%e3%81%84%e3%81%9f/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 06:30:38 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[web & pc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=931</guid>
		<description><![CDATA[以前、こんな記事を書きました。 http://life.co-hey.com/2009/02/zendframework_175_1/ その後、Zend_Mailをいじることはなかったんですが、最近また利用する機会があっ [...]]]></description>
			<content:encoded><![CDATA[<p>
以前、こんな記事を書きました。<br />
<a href="http://life.co-hey.com/2009/02/zendframework_175_1/">http://life.co-hey.com/2009/02/zendframework_175_1/</a><br />
<br />
その後、Zend_Mailをいじることはなかったんですが、最近また利用する機会があったのですが、Zend_Mailの中身を修正しなくても、文字化けしなくなっていました。<br />
<br />

<div class="wp_codebox"><table><tr id="p93122"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p931code22"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #000088;">$e</span> <span style="color: #339933;">=</span> Zend_Debug<span style="color: #339933;">::</span><span style="color: #004000;">dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$errors</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exception</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Mail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'iso-2022-jp'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test@co-hey.com'</span><span style="color: #009900;">&#41;</span>
     <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFrom</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'error@co-hey.com'</span><span style="color: #009900;">&#41;</span>
     <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSubject</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'例外が発生しました'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'iso-2022-jp'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
     <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBodyText</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mb_convert_encoding</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">htmlspecialchars_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'iso-2022-jp'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'UTF-8'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
     <span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
<br />
ErrorController.phpの中で、上記のプログラムでエラー発生箇所をメールするという用途で使っています。バージョンアップの度に、Zend_Mailを１行修正する手間がいらなくなるのはうれしいです。<br />
<br />
動作を試したのは、1.10.1ですが、いつから文字化けが解消されていたのかはわかりません。。</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20Zend_Mail%E3%81%A7%E6%96%87%E5%AD%97%E5%8C%96%E3%81%91%E3%81%97%E3%81%AA%E3%81%8F%E3%81%AA%E3%81%A3%E3%81%A6%E3%81%84%E3%81%9F%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F4nrbqxl&amp;in_reply_to_status_id=31962547674415105" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2011/01/zend_mail%e3%81%a7%e6%96%87%e5%ad%97%e5%8c%96%e3%81%91%e3%81%97%e3%81%aa%e3%81%8f%e3%81%aa%e3%81%a3%e3%81%a6%e3%81%84%e3%81%9f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMをつくり直すときに役に立ったサイト</title>
		<link>http://life.co-hey.com/2010/10/vm%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8a%e7%9b%b4%e3%81%99%e3%81%a8%e3%81%8d%e3%81%ab%e5%bd%b9%e3%81%ab%e7%ab%8b%e3%81%a3%e3%81%9f%e3%82%b5%e3%82%a4%e3%83%88/</link>
		<comments>http://life.co-hey.com/2010/10/vm%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8a%e7%9b%b4%e3%81%99%e3%81%a8%e3%81%8d%e3%81%ab%e5%bd%b9%e3%81%ab%e7%ab%8b%e3%81%a3%e3%81%9f%e3%82%b5%e3%82%a4%e3%83%88/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 07:35:51 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[web & pc]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[VM]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=899</guid>
		<description><![CDATA[プログラムテスト環境として利用していたVMのハードディスク容量が足りなくなったので、新たに作り直しました。前回は勉強のためとソースからコンパイルして作ったんですが、今回はyumを使った方法を試してみることに。 途中うまく [...]]]></description>
			<content:encoded><![CDATA[<p>
プログラムテスト環境として利用していたVMのハードディスク容量が足りなくなったので、新たに作り直しました。前回は勉強のためとソースからコンパイルして作ったんですが、今回はyumを使った方法を試してみることに。<br />
<br />
途中うまく動かない箇所があったんですが、yumリポジトリを変えて再度構築しなおしたら、意図通りに動作する環境ができあがりました。そのときに参考にしたサイトを忘れないようにメモです。<br />
<br />
いくつかのサイトを参考にしながら作成しましたが、うまくいったのはこのサイトの方法で構築したときでした。<br />
【VMware Player上のCentOSに開発環境を構築 #2CommentsAdd Star】<br />
<a href="http://rewish.org/php_mysql/vm_player_config_2">http://rewish.org/php_mysql/vm_player_config_2</a><br />
<br />
Gitのインストールの際に参考にしたサイト<br />
【centos5.3でyumを使ってgitをインストールする】<br />
<a href="http://d.hatena.ne.jp/uk_oasis/20090807/1249633626">http://d.hatena.ne.jp/uk_oasis/20090807/1249633626</a><br />
<br />
<br />
ついでに調べた、Gitのクライアント。<br />
【tortoiseGit】　tortoiseSVNのgit版。Win専用。<br />
<a href="http://code.google.com/p/tortoisegit/">http://code.google.com/p/tortoisegit/</a><br />
<br />
【SmartGit】 Win、Mac、Linuxに対応<br />
<a href="http://www.syntevo.com/smartgit/index.html">http://www.syntevo.com/smartgit/index.html</a><br />
Gitだけじゃなくて、CSV、SVNのクライアントも。慣れたら同じ使い勝手で全部いけるとしたら一番いいのかも。<br />
<br />
【Gitti】 Mac専用。画面がいい感じ。<br />
<a href="http://www.gittiapp.com/">http://www.gittiapp.com/</a></p>

<a href="http://twitter.com/?status=RT%20%40%3A%20VM%E3%82%92%E3%81%A4%E3%81%8F%E3%82%8A%E7%9B%B4%E3%81%99%E3%81%A8%E3%81%8D%E3%81%AB%E5%BD%B9%E3%81%AB%E7%AB%8B%E3%81%A3%E3%81%9F%E3%82%B5%E3%82%A4%E3%83%88%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F2dc4crb&amp;in_reply_to_status_id=26628715152" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2010/10/vm%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8a%e7%9b%b4%e3%81%99%e3%81%a8%e3%81%8d%e3%81%ab%e5%bd%b9%e3%81%ab%e7%ab%8b%e3%81%a3%e3%81%9f%e3%82%b5%e3%82%a4%e3%83%88/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>連想配列の同じkey名の値を加算する</title>
		<link>http://life.co-hey.com/2010/07/%e9%80%a3%e6%83%b3%e9%85%8d%e5%88%97%e3%81%ae%e5%90%8c%e3%81%98key%e5%90%8d%e3%81%ae%e5%80%a4%e3%82%92%e5%8a%a0%e7%ae%97%e3%81%99%e3%82%8b/</link>
		<comments>http://life.co-hey.com/2010/07/%e9%80%a3%e6%83%b3%e9%85%8d%e5%88%97%e3%81%ae%e5%90%8c%e3%81%98key%e5%90%8d%e3%81%ae%e5%80%a4%e3%82%92%e5%8a%a0%e7%ae%97%e3%81%99%e3%82%8b/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 01:48:05 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[web & pc]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=749</guid>
		<description><![CDATA[前に覚えた　func_get_args　というメソッドを使える機会があったので、使った内容をメモ。 タイトルの通り、パラメタで渡された連想配列のうち、同じkey名の値を加算します。パラメタはいくつでも渡せます。 func [...]]]></description>
			<content:encoded><![CDATA[<p>
前に覚えた　func_get_args　というメソッドを使える機会があったので、使った内容をメモ。<br />
<br />
タイトルの通り、パラメタで渡された連想配列のうち、同じkey名の値を加算します。パラメタはいくつでも渡せます。 func_get_argsのいいところ。<br />
<br />

<div class="wp_codebox"><table><tr id="p74924"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p749code24"><pre class="php" style="font-family:Osaka-mono,monospace;">    <span style="color: #666666; font-style: italic;">//-----------------------------------------------------------------</span>
    <span style="color: #666666; font-style: italic;">// パラメタで渡された配列の、同じkey名の値を合算した配列を返却する</span>
    <span style="color: #666666; font-style: italic;">//-----------------------------------------------------------------</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _arrayAdd<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// パラメタが1つ以上ない場合は処理をしない</span>
        <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<br />
</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20%E9%80%A3%E6%83%B3%E9%85%8D%E5%88%97%E3%81%AE%E5%90%8C%E3%81%98key%E5%90%8D%E3%81%AE%E5%80%A4%E3%82%92%E5%8A%A0%E7%AE%97%E3%81%99%E3%82%8B%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F39m9hky" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2010/07/%e9%80%a3%e6%83%b3%e9%85%8d%e5%88%97%e3%81%ae%e5%90%8c%e3%81%98key%e5%90%8d%e3%81%ae%e5%80%a4%e3%82%92%e5%8a%a0%e7%ae%97%e3%81%99%e3%82%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>extractという関数を見つけた</title>
		<link>http://life.co-hey.com/2010/07/extract%e3%81%a8%e3%81%84%e3%81%86%e9%96%a2%e6%95%b0%e3%82%92%e8%a6%8b%e3%81%a4%e3%81%91%e3%81%9f/</link>
		<comments>http://life.co-hey.com/2010/07/extract%e3%81%a8%e3%81%84%e3%81%86%e9%96%a2%e6%95%b0%e3%82%92%e8%a6%8b%e3%81%a4%e3%81%91%e3%81%9f/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 00:00:12 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[web & pc]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=742</guid>
		<description><![CDATA[wordpressのソースを見ていたら、extractという関数を見つけた。 詳細はこちら。http://php.net/manual/ja/function.extract.php 連想配列の、key名の変数に、vla [...]]]></description>
			<content:encoded><![CDATA[<p>
wordpressのソースを見ていたら、extractという関数を見つけた。<br />
詳細はこちら。<a href="http://php.net/manual/ja/function.extract.php">http://php.net/manual/ja/function.extract.php</a><br />
<br />
連想配列の、key名の変数に、vlaueの値をつっこんでくれる関数。<br />
今まで、<br />
<br />

<div class="wp_codebox"><table><tr id="p74227"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p742code27"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$key3</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$list</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
のように書いてた部分が、<br />
<br />

<div class="wp_codebox"><table><tr id="p74228"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p742code28"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$list</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
というようにもかける。<br />
<br />
listだと、変数の数を動的に増やしたいときに不便だと感じるときがあったので、そういうときの代替案として使えそう。</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20extract%E3%81%A8%E3%81%84%E3%81%86%E9%96%A2%E6%95%B0%E3%82%92%E8%A6%8B%E3%81%A4%E3%81%91%E3%81%9F%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F28jtxh6" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2010/07/extract%e3%81%a8%e3%81%84%e3%81%86%e9%96%a2%e6%95%b0%e3%82%92%e8%a6%8b%e3%81%a4%e3%81%91%e3%81%9f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpで子クラスへ__constructのパラメタを渡す</title>
		<link>http://life.co-hey.com/2010/04/php%e3%81%a7%e5%ad%90%e3%82%af%e3%83%a9%e3%82%b9%e3%81%b8__construct%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%82%bf%e3%82%92%e6%b8%a1%e3%81%99/</link>
		<comments>http://life.co-hey.com/2010/04/php%e3%81%a7%e5%ad%90%e3%82%af%e3%83%a9%e3%82%b9%e3%81%b8__construct%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%82%bf%e3%82%92%e6%b8%a1%e3%81%99/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 02:51:40 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[web & pc]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=581</guid>
		<description><![CDATA[今までは、配列で渡してたんですが、違和感があるので、どうにか__constructに渡した形と同じように _initにも渡せないかなと考えて、以下のようにしました。 意図通りに動いてくれています。５個以上パラメタがあると [...]]]></description>
			<content:encoded><![CDATA[<p>
今までは、配列で渡してたんですが、違和感があるので、どうにか__constructに渡した形と同じように _initにも渡せないかなと考えて、以下のようにしました。<br />
<br />
意図通りに動いてくれています。５個以上パラメタがあるときも稀だと思うので、５個までにしています。増えたら増やせばいいかなと。これで違和感なく使えるようになってすっきりです。<br />
<br />

<div class="wp_codebox"><table><tr id="p58130"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p581code30"><pre class="php" style="font-family:Osaka-mono,monospace;">abstract <span style="color: #000000; font-weight: bold;">class</span> Hoge_Model_Abstract
<span style="color: #009900;">&#123;</span>
    final <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// ここに共通初期化処理</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">func_num_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param3</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param4</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param5</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_init<span style="color: #009900;">&#40;</span><span style="color: #000088;">$param1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param3</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param4</span><span style="color: #339933;">,</span> <span style="color: #000088;">$param5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// 初期化処理するときはこちらで</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<br />
</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20php%E3%81%A7%E5%AD%90%E3%82%AF%E3%83%A9%E3%82%B9%E3%81%B8__construct%E3%81%AE%E3%83%91%E3%83%A9%E3%83%A1%E3%82%BF%E3%82%92%E6%B8%A1%E3%81%99%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F2g3wdlq" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2010/04/php%e3%81%a7%e5%ad%90%e3%82%af%e3%83%a9%e3%82%b9%e3%81%b8__construct%e3%81%ae%e3%83%91%e3%83%a9%e3%83%a1%e3%82%bf%e3%82%92%e6%b8%a1%e3%81%99/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>filterに使えるarray_intersect_key</title>
		<link>http://life.co-hey.com/2010/03/filter%e3%81%ab%e4%bd%bf%e3%81%88%e3%82%8barray_intersect_key/</link>
		<comments>http://life.co-hey.com/2010/03/filter%e3%81%ab%e4%bd%bf%e3%81%88%e3%82%8barray_intersect_key/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 04:15:23 +0000</pubDate>
		<dc:creator>co-hey</dc:creator>
				<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://life.co-hey.com/?p=576</guid>
		<description><![CDATA[第一パラメタの配列の中で、第２パラメタ以降の配列全てに存在するキーのものだけ取得してくれる。 詳しい説明はこちらで。 http://php.net/manual/ja/function.array-intersect-k [...]]]></description>
			<content:encoded><![CDATA[<p>
第一パラメタの配列の中で、第２パラメタ以降の配列全てに存在するキーのものだけ取得してくれる。<br />
<br />
詳しい説明はこちらで。<br />
<a href="http://php.net/manual/ja/function.array-intersect-key.php">http://php.net/manual/ja/function.array-intersect-key.php</a><br />
<br />
今まで、Zend_Db_Table_RowのsetFromArrayの存在を知らなかったので、自分でこんなやりかたでfilterしてました。<br />
<br />

<div class="wp_codebox"><table><tr id="p57633"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p576code33"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     
<span style="color: #000088;">$table</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Db_Table_Abstractを継承したクラス<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cols</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cols'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cols</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<br />
<br />
<br />
これが、<br />
<br />

<div class="wp_codebox"><table><tr id="p57634"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p576code34"><pre class="php" style="font-family:Osaka-mono,monospace;"><span style="color: #000088;">$table</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Db_Table_Abstractを継承したクラス<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cols</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cols'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_intersect_key</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span><span style="color: #339933;">,</span> <span style="color: #990000;">array_flip</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cols</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<br />
<br />
と書けます。これ便利ですね。<br />
<br />
ZendFrameworkのソースに書いてありました。<br />
なんで今まで見つけれなかったんだろう。必要としてなかったからなのか。<br />
もっと楽な方法がないのかって思えてなかったことに反省。</p>

<a href="http://twitter.com/?status=RT%20%40%3A%20filter%E3%81%AB%E4%BD%BF%E3%81%88%E3%82%8Barray_intersect_key%20-%20Life%20http%3A%2F%2Ftinyurl.com%2F27vmvjp" class="tweet-this" ><img src="http://life.co-hey.com/wp-content/plugins/simple-tweet/img/tweet.gif" title="つぶやく" alt="つぶやく" /></a>]]></content:encoded>
			<wfw:commentRss>http://life.co-hey.com/2010/03/filter%e3%81%ab%e4%bd%bf%e3%81%88%e3%82%8barray_intersect_key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

