<?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>arkinEx Codex &#187; PHP</title>
	<atom:link href="http://www.arkinex.com/contains/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arkinex.com</link>
	<description>the place where all my code can be viewed</description>
	<lastBuildDate>Wed, 04 Nov 2009 20:39:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP Function: array_trim</title>
		<link>http://www.arkinex.com/php/functions/124/php-function-array_trim/</link>
		<comments>http://www.arkinex.com/php/functions/124/php-function-array_trim/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 20:39:07 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
				<category><![CDATA[Functions]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[array_trim]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/?p=124</guid>
		<description><![CDATA[I was loading alot of data from .csv files, some of the data was blank and i didnt want array key=&#62;values for it, so i created an multi dimensional array cleansing tool. function array_trim&#40;&#38;$a&#41;&#123; foreach&#40; $a as $k =&#62; $v &#41; &#123; if &#40; is_array&#40; $a&#91;$k&#93; &#41; &#41; array_trim&#40; $a&#91;$k&#93; &#41;; else $a&#91;$k&#93; = trim&#40; [...]]]></description>
			<content:encoded><![CDATA[<p>I was loading alot of data from .csv files, some of the data was blank and i didnt want array key=&gt;values for it, so i created an multi dimensional array cleansing tool.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> array_trim<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$a</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</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;">is_array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> array_trim<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$v</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;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> 
<span style="color: #666666; font-style: italic;">// Useage:</span>
array_trim<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$a</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/php/functions/124/php-function-array_trim/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Convert time (hr:min:secs) into seconds</title>
		<link>http://www.arkinex.com/php/snippets/47/convert-time-into-duration-seconds/</link>
		<comments>http://www.arkinex.com/php/snippets/47/convert-time-into-duration-seconds/#comments</comments>
		<pubDate>Sun, 14 Sep 2008 23:33:47 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[duration]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[thumbnail]]></category>
		<category><![CDATA[timestamp]]></category>
		<category><![CDATA[video editing]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/?p=47</guid>
		<description><![CDATA[I wrote this snippet to convert ffmpeg&#8217;s information output time into seconds, i can then determine the 25, 50 and 75 percentages to create 3 different thumbnails of a movie (using ffmpeg also). Heres the snippet: function time2seconds&#40;$time='00:00:00'&#41;&#123; list&#40;$hr,$m,$s&#41; = explode&#40;':', $time&#41;; return &#40; &#40;int&#41;$hr*3600 &#41; + &#40; &#40;int&#41;$m*60 &#41; + &#40;int&#41;$s; &#125; Hope you [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this snippet to convert ffmpeg&#8217;s information output time into seconds, i can then determine the 25, 50 and 75 percentages to create 3 different thumbnails of a movie (using ffmpeg also).</p>
<p>Heres the snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> time2seconds<span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'00:00:00'</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;">$hr</span><span style="color: #339933;">,</span><span style="color: #000088;">$m</span><span style="color: #339933;">,</span><span style="color: #000088;">$s</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: #0000ff;">':'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$time</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$hr</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">3600</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$m</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">60</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$s</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Hope you find this as useful as I have.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/php/snippets/47/convert-time-into-duration-seconds/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Automatically Version your Javascript &amp; Stylesheets</title>
		<link>http://www.arkinex.com/guides/36/auto-version-javascript-stylesheets/</link>
		<comments>http://www.arkinex.com/guides/36/auto-version-javascript-stylesheets/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 17:34:06 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
				<category><![CDATA[Guides]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[stylesheet]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/?p=36</guid>
		<description><![CDATA[Recently, I was browsing the internet, as you do, and I came across a great little article that discussed the automatic versioning of stylesheets, javascript, flash and image files. As i constantly have to hold shift when refreshing to get a full page refresh, I decided this method was genius and decided there were a [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was browsing the internet, as you do, and I came across a great little article that discussed the automatic versioning of stylesheets, javascript, flash and image files.</p>
<p>As i constantly have to hold shift when refreshing to get a full page refresh, I decided this method was genius and decided there were a few things needed to make it perfect.<br />
<span id="more-36"></span><br />
First of all, I couldn&#8217;t get the cache code which goes in .htaccess to work, after closer inspection you must make sure mod_expires is enabled on your server (if you run your own), otherwise you will see a 500 error.</p>
<p>Secondly, the autoVer ended up breaking my javascript and stylesheet files as I name them with multiple periods and it was subsequently replacing them all with numbers so i ended up with filenames like <em>framework.1230203232.version.21302302.two.js</em> which is a bit over the top.</p>
<p>Anyway, this is my revised version, for those of you who haven&#8217;t read <a href="http://particletree.com/notebook/automatically-version-your-css-and-javascript-files/">Particletree</a>, you don&#8217;t necessarily need to, I will cover all the required parts.</p>
<p>First of all, we modify <em>.htaccess</em> so that it sets an expiry date on all stylesheets, images and javascript files.</p>
<p><em>.htaccess</em></p>
<pre class="Style">&lt;FilesMatch "\.(gif|png|jpg|js|css|swf)$"&gt;
    ExpiresActive On
    ExpiresDefault "access plus 10 years"
&lt;/FilesMatch&gt;
#Rules for the versioned files
RewriteRule ^(scripts|css|images)/(.+)\.([a-zA-Z0-9]+)\.(js|css|jpg|gif|png)$ $1/$2.$4 [L]</pre>
<p>This will make all images, stylesheets, flash and javascript cache for 10 years (reduces load on your server and bandwidth costs) and also adds the <em>RewriteRule</em> which handles the version file pointing to the normal files.</p>
<p>Next, we want to add the function, ideally you want this defined on every page, so stick it somewhere good.</p>
<p><em>the Auto Version function</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> autoVer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</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;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$f</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">base_convert</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">filemtime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'DOCUMENT_ROOT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">36</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span><span style="color: #990000;">strrpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In the case that php cannot find the file, it still might exist, so the function just returns the parameters it was given.</p>
<p>Next, we rewrite the <em>HEAD</em> part of your html, this file must be <em>PHP</em> for it to work, and the function must be included (either at the top of the page or within another file).</p>
<p><em>My HEAD area</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>head<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>title<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>arkinEx<span style="color: #339933;">.</span>com <span style="color: #339933;">-</span> Autoversion Your Javascript <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span> CSS Stylesheets<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>title<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content-type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=UTF-8&quot;</span> <span style="color: #339933;">/&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>meta name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;author&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;arkinEx&quot;</span> <span style="color: #339933;">/&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>link rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;stylesheet&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?=autoVer('/resources/stylesheets/design.css')?&amp;gt;&quot;</span> <span style="color: #339933;">/&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?=autoVer('/resources/javascript/mootools-core.js')?&amp;gt;&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;/</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?=autoVer('/resources/javascript/mootools-more.js')?&amp;gt;&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;/</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&amp;lt;?=autoVer('/resources/javascript/mootools-pastejax.js')?&amp;gt;&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;/</span>script<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>
<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;/</span>head<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Which, then, will produce a nice output something like this:<br />
&lt;pre lang=&#8221;html&#8221;&gt;<br />
&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;/resources/stylesheets/design.aHegDd.css&#8221; /&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;/resources/javascript/mootools-core.a45S.js&#8221;&gt;&lt;/script&gt;</p>
<p>You get the idea, so try it out, let me know how you found it.</p>
<p>The Original Article: &#8220;<a href="http://particletree.com/notebook/automatically-version-your-css-and-javascript-files/">Automatically Version Your CSS and Javascript Files</a>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/guides/36/auto-version-javascript-stylesheets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Benchmark your PHP code</title>
		<link>http://www.arkinex.com/php/34/benchmark-your-php-code/</link>
		<comments>http://www.arkinex.com/php/34/benchmark-your-php-code/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 11:51:44 +0000</pubDate>
		<dc:creator>arkin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.arkinex.com/?p=34</guid>
		<description><![CDATA[As a developer I often question myself when I have many occurrences of a function that could be replaced by something else. There are often many ways of achieving the same thing and only opinion standing in the way of a decision. To solve this problem, I often benchmark certain peices of code multiple times [...]]]></description>
			<content:encoded><![CDATA[<p>As a developer I often question myself when I have many occurrences of a function that could be replaced by something else. There are often many ways of achieving the same thing and only opinion standing in the way of a decision.</p>
<p>To solve this problem, I often benchmark certain peices of code multiple times to see which comes out the fastest. In this guide/tutorial I will teach you how to benchmark your own code.</p>
<p><span id="more-34"></span><br />
The first step is to decide what you want to benchmark, I had trouble in figuring out what to test in this benchmark so in this example I am going to do a simple comparison of using <a href="http://php.net/sizeof">sizeOf</a> inside a for loop and outside a for loop.</p>
<p>The second step is to decide how many times you want to repeat a block of code, if its a larger and more intense block I sugget fewer times, for a shorter block, i recommend more times. In this example I have done 100 times to produce a noticably different output time.</p>
<p>The first part of the code which uses sizeOf inside the for loop:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* PUT THE CODE TO BENCHMARK BELOW */</span>
&nbsp;
	<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$a</span><span style="color: #339933;">&lt;</span>sizeOf<span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$a</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* END OF BENCHMARK CODE */</span>
<span style="color: #009900;">&#125;</span> <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%01.2fms'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Notice, it is important to unset the variables that were set during the test to make it fair.</p>
<p>The second test will be with the <a href="http://php.net/sizeof">sizeOf</a> element outside of the <a href="http://php.net/for">for loop</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* PUT THE CODE TO BENCHMARK BELOW */</span>
&nbsp;
	<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sizeOf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000088;">$a</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$s</span><span style="color: #339933;">;</span><span style="color: #000088;">$a</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* END OF BENCHMARK CODE */</span>
<span style="color: #009900;">&#125;</span> <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #339933;">,</span><span style="color: #000088;">$i</span><span style="color: #339933;">,</span><span style="color: #000088;">$x</span><span style="color: #339933;">,</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%01.2fms'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Also, notice, the only thing that changed here was the addition of <em>$s = sizeOf($x);</em> and the changed variable in the <a href="http://php.net/for">for loop</a>.</p>
<p>The ouput of this test was quite significant:</p>

<div class="wp_syntax"><div class="code"><pre class="result" style="font-family:monospace;">2.06ms
0.96ms</pre></div></div>

<p>As you can see from the results, the sizeOf is best kept outside of the for loop (cached in a variable), so it is not repeated each time.</p>
<p>I hope this guide has helped, I will post the file online later for download and will be doing a more advanced guide on benchmarking in the next few days.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arkinex.com/php/34/benchmark-your-php-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
