<?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>Ash Searle's Blog</title>
	<atom:link href="http://hexmen.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://hexmen.com/blog</link>
	<description>On programming, and other things...</description>
	<lastBuildDate>Thu, 03 Dec 2009 10:29:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript Date to&#160;Time</title>
		<link>http://hexmen.com/blog/2009/12/javascript-date-to-time/</link>
		<comments>http://hexmen.com/blog/2009/12/javascript-date-to-time/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 10:29:14 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=98</guid>
		<description><![CDATA[Subtle differences sometimes indicate the proficiency of a programmer.
Here are three ways to get the current time in JavaScript:
var t1 = (new Date()).getTime(); // 1
var t2  = new Date().getTime(); // 2
var t3 = (new Date).getTime(); // 3


The bracket placement is as much about language awareness as personal taste.  In JavaScript, the brackets are [...]]]></description>
			<content:encoded><![CDATA[<p>Subtle differences sometimes indicate the proficiency of a programmer.</p>
<p>Here are three ways to get the current time in JavaScript:</p>
<pre class="javascript"><code>var t1 = (new Date()).getTime(); // 1
var t2  = new Date().getTime(); // 2
var t3 = (new Date).getTime(); // 3

</code></pre>
<p>The bracket placement is as much about language awareness as personal taste.  In JavaScript, the brackets are optional for a zero-argument constructor: <code>new Date</code> creates a new <code>Date</code> instance without requiring brackets.  But due to JavaScript operator precedence, you can&#8217;t write <code>new Date.getTime()</code> because the interpreter sees that as trying to call the constructor for a <code>Date.getTime</code> class (cf. <code>MyPackage.MyClass</code>) &#8211; in this case the brackets are required for the statement to parse as intended.</p>
<p>Reflecting on the three versions above: Version 1 doesn&#8217;t do anything to show a deep understanding of JavaScript.  Version 2 and 3 are sort of interchangeable, but version 3 just edges ahead because the coder&#8217;s displayed knowledge to drop the optional brackets.</p>
<p>Of course, if you want the most compact code possible, you&#8217;d write:</p>
<pre class="javascript"><code>var t4 = +new Date; // 4

</code></pre>
<p>This little gem creates a new Date, then coerces it into a number using a unary <code>+</code> operator &#8211; and coercing a Date to a number is defined in the language spec to go via <code>valueOf</code> and <code>getTime</code>.</p>
<p>Checking the character-count: <code>(new Date).getTime()</code> is 20 characters, while <code>+new Date</code> is 9.</p>
<p>That 11 character saving might come in handy on, say, the new Google home-page, where they currently use <code>(new Date).getTime()</code> <em>seven times</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2009/12/javascript-date-to-time/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>AppleScript &#8211; a frustrating&#160;beginning</title>
		<link>http://hexmen.com/blog/2009/04/applescript-a-frustrating-beginning/</link>
		<comments>http://hexmen.com/blog/2009/04/applescript-a-frustrating-beginning/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 16:01:10 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[AppleScript]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=84</guid>
		<description><![CDATA[Academia and professional work has exposed me to a few different programming paradigms: functional, logical, procedural and object-orientated.  I usually get along fine with a new paradigm, starting off with a few example programs and hacking away at them to get a decent grasp of the language.  But, I&#8217;m not getting anywhere with [...]]]></description>
			<content:encoded><![CDATA[<p>Academia and professional work has exposed me to a few different programming paradigms: functional, logical, procedural and object-orientated.  I usually get along fine with a new paradigm, starting off with a few example programs and hacking away at them to get a decent grasp of the language.  But, I&#8217;m not getting anywhere with AppleScript &#8211; it&#8217;s a frustrating beastie!</p>
<p>I think the root cause is the documentation.  A quick read of <a href="http://en.wikipedia.org/wiki/AppleScript">wikipedia&#8217;s page on AppleScript</a> shows you you&#8217;re dealing with a <em>natural language</em>.  AppleScript statements read like english sentences with padding words like &#8220;the&#8221; being optional, for example: <code>tell application "Finder" to say the name of the front Finder window as string</code>.</p>
<p>Maybe I&#8217;m being mislead because I&#8217;m holding onto <a href="http://www.apple.com/support/tiger/">Tiger</a> while waiting for <a href="http://www.apple.com/macosx/snowleopard/">Snow Leopard</a> &#8211; I can&#8217;t see why you&#8217;d need to use <code>as string</code> at the end of the example given?  A Finder window&#8217;s name property is documented as unicode text and yet I need to explicitly convert it to a string (or equivalently and for no good reason <code>as text</code> works too).  It&#8217;s rubbish!</p>
<p>Accesing properties is a little odd too;  I&#8217;m not even sure whether AppleScripts trying to be object-oreiented or not. We can rewrite the example to use a posessive <code>'s</code> instead of the <code>of</code> operator.  e.g. <code>tell app "Finder" to say front Finder window's name as text</code> &#8211; which is nice.  But sometimes it works, and sometimes it doesn&#8217;t.   (note: I arbitrarily abbreviated <code>application</code> to <code>app</code>, but I&#8217;ve no idea where to find a full list of supported abbreviations&#8230;!)</p>
<p>I don&#8217;t grok the Script Editor at all.  You can easily inspect the command, classes and properties supported by an application, but where the hell&#8217;s the core language documentation?  Where do you go to find out &#8211; when it comes to strings &#8211; <code>count</code> is a method, but <code>length</code> is a property?  <code>count "some string"</code>  is OK, but <code>count <em>of</em> "some string"</code> isn&#8217;t!  How do I find a list of all properties of the AppleScript class &#8211; or any other arbitrary class, record or structure?</p>
<p>In the days and weeks ahead I hope to progress to such <em>advanced</em> topics as:</p>
<ul>
<li>writing arbitrary text to standard output (<a href="http://groups.google.com/group/alt.comp.lang.applescript/browse_thread/thread/d6fd2cd13927d5b3/5cba6813346a1750">this doesn&#8217;t work</a> and I&#8217;d like to write to standard output whenever I need to, not solely at the end of the program.)</li>
<li>checking a file exists (without using Finder or throwing an error)</li>
<li>list files in a directory (without using <code>do shell script</code> or using Finder)</li>
<li>get the urls of all tabs of all windows of safari (<code>tell app "Safari" to get URL of every document</code> only shows one URL per window, and my natural language instinct to use <code>every document of every tab of every window</code> falls flat on its face&#8230;)</li>
<li>access the <code>/dev</code> directory (<code>POSIX file "/usr" as alias</code> is fine, <code>POSIX file "<strong>/dev</strong>" as alias</code> throws an error!  WTF!?)</li>
</ul>
<p>To end on a semi-useful note, here are some very basic things I&#8217;ve discovered while developing AppleScript&#8217;s in a terminal window:</p>
<dl>
<dt>Determine AppleScript version number</dt>
<dd><code>$ osascript -e "AppleScript's version"</code></dd>
<dt>Show current track name from iTunes</dt>
<dd>(Note: I&#8217;m coming round to the idea that using <code>$'...'</code> is the best way of wrapping the applescript on a bash command-line &#8211; it allows you to backslash escape single-quotes and keep your double-quotes handy for literal strings.)<br />
<code>$ osascript -e $'tell application "iTunes" to get current track's name'</code>
</dd>
</dl>
<p>(you&#8217;d think there&#8217;d be more&#8230;)</p>
<p>I&#8217;ll follow up with another AppleScript article once I&#8217;ve mastered the art of controlling iTunes to extract artwork and iterate over albums and artists.</p>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2009/04/applescript-a-frustrating-beginning/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>All-in-one cookie&#160;function</title>
		<link>http://hexmen.com/blog/2009/03/all-in-one-cookie-function/</link>
		<comments>http://hexmen.com/blog/2009/03/all-in-one-cookie-function/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 10:18:06 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=75</guid>
		<description><![CDATA[Users stumbling across jQuery may notice the API&#8217;s designed so a method&#8217;s behaviour varies depending on the number and type of arguments passed in a call (have a look at the jQuery method!).  In the right hands, this flexibility produces clean and elegant code without burdening the developer with 101 new method names to [...]]]></description>
			<content:encoded><![CDATA[<p>Users stumbling across jQuery may notice the API&#8217;s designed so a method&#8217;s behaviour varies depending on the number and type of arguments passed in a call (have a look at the <a href="http://docs.jquery.com/Core/jQuery">jQuery method</a>!).  In the right hands, this flexibility produces clean and elegant code without burdening the developer with 101 new method names to learn.</p>
<p>Let&#8217;s do the same for cookies (source: <a href="http://hexmen.com/js/cookie.js">cookie.js</a>).</p>
<h3>Three into one does go</h3>
<p>Googling for &#8216;<a href="http://www.google.com/search?q=javascript+cookie+functions">javascript cookie functions</a>&#8216; brings back Peter-Paul Koch&#8217;s trio of functions from <a href="http://www.quirksmode.org/js/cookies.html">QuirksMode</a>.  The functions are named <code>setCookie</code>, <code>readCookie</code> and <code>eraseCookie</code>.  Browsing through the next few search-results we see the same thing going by different names: <code>get</code>, <code>set</code> and <code>deleteCookie</code>; <code>add</code> &#038; <code>remove</code>, <code>erase</code> &#038; <code>delete</code>, <code>read</code>, <code>get</code> and <code>check</code> &#8211; all variations on a theme, all separating functionality into a trio of functions.</p>
<p>Let&#8217;s look at the method signatures:</p>
<ul>
<li><code>createCookie(<em>name</em>, <em>value</em>, <em>days</em>)</code></li>
<li><code>readCookie(<em>name</em>)</code></li>
<li><code>eraseCookie(<em>name</em>)</code></li>
</ul>
<p>It&#8217;s pretty basic stuff.</p>
<p>To merge the three functions into one, we have to differentiate between reading, writing and deleting a cookie by the number and value of arguments; I&#8217;ve chosen an implementation where deleting a cookie is achieved by setting it to <code>null</code>.</p>
<p>Here&#8217;s some example usage:</p>
<pre><code>  // create a cookie:
  cookie('name', 'value');

  // read it:
  alert(cookie('name'));

  // erase it:
  cookie('name', null);

</code></pre>
<h3>Flexibility</h3>
<p>All those cookie calls pass at least one parameter&#8230; but isn&#8217;t there something useful we can do with a plain parameterless <code>cookie()</code> call?  Of course there is &#8211; let&#8217;s return an associative array of all cookie values!</p>
<p>By default (without specifying an explicit expiry time) cookies survive until you restart the browser.  It&#8217;s kinda mandatory to provide some way of specifying an <strong>expiry</strong> time.</p>
<p>We&#8217;ll accept an <em>optional</em> third parameter specifying an expiry time in <em>days</em>:</p>
<pre><code>  // create cookie for 1 year
  cookie('theme', 'minimal', 365);

  // grab all cookies:
  var cookies = cookie();
  alert(cookies.theme);

</code></pre>
<p>Looking good so far.  But there&#8217;s more.</p>
<p>Like several of the cookie libraries, our function defaults to setting cookies on the top-level path &#8220;/&#8221; &#8211; this is a more common requirement than the browsers default behaviour, which sets a cookie so it&#8217;s only used at or below the current page level (i.e. a cookie set while looking at &#8220;<a href="http://ewelike.com/products/Nintendo-DSi-Console_Black/978372">/products/Nintendo-DSi-Console_Black/978372</a>&#8221; wouldn&#8217;t be available when looking at any other product.)</p>
<p>To give developers flexibility I&#8217;ve made <strong>path</strong> another <em>optional</em> parameter &#8211; it could be used to share cookies between &#8220;/product/*&#8221; pages, but withhold them from any other area of a site.</p>
<p>While we&#8217;re on the subject of sharing &#8211; what about cross-domain cookies?  Cookies are naturally assigned to the domain the page is being viewed on, but sometimes we want to make sure a cookie&#8217;s available to all sub-domains too.  <strong>domain</strong> is also an <em>optional</em> parameter.</p>
<p>Having both <em>path</em> and <em>domain</em> as optional parameters could be confusing &#8211; after all, they&#8217;re both strings.  Fortunately, we know paths begin with &#8216;/&#8217; and domains don&#8217;t &#8211; and if you want to specify both you just stick to the right order: <em>path</em> then <em>domain</em>:</p>
<pre><code>  // share cookie between product pages:
  cookie('view-description', 'hidden', '/products');

  // share cookie between domains:
  cookie('id', '_', '.ewelike.com');

  // save preferences cross-domain for 1 year:
  cookie('prefs', '_', 365, '/products', '.ewelike.com');

</code></pre>
<p>Finally, there&#8217;s an optional &#8217;secure&#8217; parameter.  I&#8217;ve never used this myself, but it&#8217;s there if you want it.  It&#8217;s handy if you&#8217;re storing sensitive information in cookies and you only want to allow the browser to transfer the cookie value when it&#8217;s request pages via https.  The code will take any <em>truthy</em> value hanging off the end of the parameters (anything that&#8217;s not been interpreted as expiry date, path or domain.):</p>
<pre><code>  // set a secure cookie on the default path and domain
  // (expires when the browser closes)
  cookie('name', 'value', true);

</code></pre>
<p>Want the code?  Grab it now&#8230; <a href="http://hexmen.com/js/cookie.js">download cookie.js</a> (dual-licensed under MIT and GPL, exactly the same as jQuery)</p>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2009/03/all-in-one-cookie-function/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>The MacBook Pro&#8217;s not so&#160;bad&#8230;</title>
		<link>http://hexmen.com/blog/2009/02/macbook-pro-not-so-bad/</link>
		<comments>http://hexmen.com/blog/2009/02/macbook-pro-not-so-bad/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 11:36:15 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=72</guid>
		<description><![CDATA[Two years after moaning about my MacBook Pro I figure it&#8217;s time for an update:
It&#8217;s not so bad&#8230;
Thanks to various blog comments I managed to solve most of the niggles I had with the laptop:

muted the startup sound
This was pretty straight forward: download StartupSound.prefPane and choose the appropriate settings (I ticked the &#8220;Mute&#8221; box next [...]]]></description>
			<content:encoded><![CDATA[<p>Two years after <a href="http://hexmen.com/blog/2007/02/i-hate-my-macbook-pro/">moaning about my MacBook Pro</a> I figure it&#8217;s time for an update:</p>
<p>It&#8217;s not so bad&#8230;</p>
<p>Thanks to various blog comments I managed to solve most of the niggles I had with the laptop:</p>
<dl>
<dt>muted the startup sound</dt>
<dd>This was pretty straight forward: download <a href="http://www5e.biglobe.ne.jp/~arcana/software.en.html">StartupSound.prefPane</a> and choose the appropriate settings (I ticked the &#8220;Mute&#8221; box next to &#8220;Startup Volume&#8221; which seems to work fine.)</dd>
<dt>reconfigured keyboard layout using Ukulele</dt>
<dd>(definitely a personal preference) I configured a <a href="http://en.wikipedia.org/wiki/Keyboard_layout">keyboard layout</a> to match UK PC keyboards: backtick (<code>`</code>) to the left of <kbd>1</kbd>, hash# and tilde~ next to return, at@ and double-quote&#8221; reversed (double-quote via <kbd>Shift+2</kbd>) and finally (I think) putting backslash and pipe| to the left of <kbd>Z</kbd>)  If you want it, you can <a href="http://hexmen.com/uploads/British%20PC.keylayout">download my British PC keyboard layout</a> (if I remember right, you have to move the file into <code>/System/Library/Keyboard Layouts/</code> and may need to restart before you can choose it in System Preferences / International / Input Menu &#8211; and if you want a decent icon you&#8217;ll need the <a href="http://hexmen.com/uploads/British%20PC.icns">flag icon</a> to bung in the <code>Keyboard Layouts</code> folder too.)</p>
<p>There is still one rather annoying aspect of the keyboard layout: it changes back to a Mac layout whenever I use <a href="http://www.opera.com">Opera</a> and tab into a password field &#8211; god knows what that&#8217;s all about!?  I&#8217;ve got used to it now though and can quickly change back with <kbd>Apple+Space</kbd></p>
</dd>
<dt>Better sleep &#038; hibernate</dt>
<dd>Apple must have distributed a software update including fixes so waking up from sleep became a lot faster and more reliable.  I&#8217;ve been months without shutting my Mac down, though I&#8217;ve recently changed my power settings so it goes into stand-by if I close the lid while plugged in, but goes into deep sleep if I close the lid while running off battery.  What I&#8217;d really like is a way to say &#8220;go into stand-by for 15 minutes, then go into deep-sleep&#8221; &#8211; I think that&#8217;d be better when you&#8217;re running of battery and carting your computer from room to room &#8211; but want it to go into deep-sleep if you hit the motorway for 2 hours.</dd>
<dt>Region-free DVD</dt>
<dd>Hackers are great.  About 8 months on from writing my bitch-post someone pointed out some a <a href="http://forum.rpc1.org/viewtopic.php?t=43012&#038;start=0">forum thread pointing to new firmware</a>.  Upgrading the firmware and installing <a href="http://xvi.rpc1.org/">Region X</a> means I can actually view DVDs I paid for&#8230; (Is that a &#8220;w00t!&#8221; I hear at the back?)</dd>
</dl>
<p>It&#8217;s nice to have been pointed to solutions by readers, but there were a couple of physical issues readers couldn&#8217;t fix: the position of the drive slot, and the crappy return key.</p>
<p>( I realise I&#8217;m only one of a million voices shouting in the wind, but) Apple have redesigned the new MacBook Pros to put the DVD slot where it should be (on the side) and they&#8217;ve added an option to let you specify a US keyboard when you order a Mac online (giving chunky <kbd>Return</kbd> and <kbd>Shift</kbd> keys, and proper labelling to say <strong>META</strong>, <strong>ALT</strong> and <strong>OPTION</strong>)</p>
<p>I need to test-drive the new chicklet keyboard before deciding whether I&#8217;d be happy using a new MacBook Pro, but with the US keyboard layout and another region-free DVD hack, I think I&#8217;d quite happily upgrade.  Of course Apple have made some changes that put me off too:</p>
<ol>
<li>you have to pay <em>more</em> for a matte display (it used to be the other way round: glossy screens cost more, but designers prefer matte displays for better colour accuracy, so Apple made the most common and desirable option the one that costs a premium.  That&#8217;s business!)</li>
<li>unremovable battery.  On some days that doesn&#8217;t sound so bad: the pro (long battery life) outweighs the con (high one-off replacement cost after 3-4 years.)  But&#8230; I&#8217;ve been through the experience of defective batteries: my original MBP battery got burning hot and buckled over the course of a few months.  I&#8217;d hate to think what would happen if the battery was wrapped around the PCB and pushing against all edges of a one-piece case.</li>
<li>non-upgradeable memory.  Well, kinda.  This is a consequence of a non-removable battery &#8211; the option to upgrade from 4 to 8GB looks like it has to be done at the point of ordering, and for a hefty charge.  Then again&#8230; 4GB of memory ought to be just fine, and (if it really comes down to it) I&#8217;m sure there&#8217;ll be a 32-step upgrade guide to replace the memory modules as soon as a memory supplier begins to sell them.</li>
</ol>
<p>All in all, I&#8217;m pretty happy with my MacBook Pro these days.  I get on better with OS X then Windows for a couple of reasons.  I prefer Apple subtle nudge reminding you there&#8217;s a monthly / bi-monthly software update ready to install &#8211; compare that to Microsoft&#8217;s randomly timed &#8220;I&#8217;m gonna restart your computer in 5 minutes&#8221; auto-upgrade annoyance (and yes, I&#8217;m well aware of &#8220;<code>net stop wuauserv</code>&#8221; to stop the nagging &#8211; I can&#8217;t remember how many times I&#8217;ve had to type that in.)  Plus, the BSD / *nix nature of OS X allows me to setup a development environment that behaves much closer to our live <a href="http://www.centos.org">CentOS</a> servers than <a href="http://www.cygwin.com">Cygwin</a> on Windows does.</p>
<p>I bought a Mac Mini last summer while rumours of a new revision were reaching fever pitch &#8211; I&#8217;m glad I didn&#8217;t wait.  The Mini&#8217;s been an absolute pleasure &#8211; running damn-near silently and without issues.  But that&#8217;s wandering off track.</p>
<p>I do have a new hate though: Sky HD.  Compared to my recently deceased TiVo, SkyHD is one of the most incompetent PVRs I&#8217;ve ever had the displeasure of using.  The only reason I haven&#8217;t cancelled my Sky subscription completely is because (as far as I know) there&#8217;s no other way to get Sky 1 &#8211; and I do like Lost, 24, Battlestar Gallactica and all the big American productions that come to Sky first&#8230;</p>
<p>And now I&#8217;m <em>really</em> off track.  Sky HD&#8217;s a gripe for another day&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2009/02/macbook-pro-not-so-bad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Concatenating arrays in&#160;PHP</title>
		<link>http://hexmen.com/blog/2008/11/concatenating-arrays-in-php/</link>
		<comments>http://hexmen.com/blog/2008/11/concatenating-arrays-in-php/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 11:46:48 +0000</pubDate>
		<dc:creator>Ash</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://hexmen.com/blog/?p=69</guid>
		<description><![CDATA[Just a quick post so I know where to look the next time I forget how to concatenate arrays in PHP.
Use array_merge to concatenate two numerically-indexed arrays; not array_push and not the array union operator: +.

$first = array('doh', 'ray', 'me');
$second = array('fah', 'soh', 'lah', 'te', 'do');

echo "Union: ", var_export($first + $second, true), "n";
echo "Merge: ", [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick post so I know where to look the next time I forget how to concatenate arrays in PHP.</p>
<p>Use <a href="http://php.net/array_merge"><code>array_merge</code></a> to concatenate two numerically-indexed arrays; not <a href="http://php.net/array_push"><code>array_push</code></a> and not <a href="http://php.net/language.operators.array">the array union operator: <code>+</code></a>.</p>
<pre><code class="php">
$first = array('doh', 'ray', 'me');
$second = array('fah', 'soh', 'lah', 'te', 'do');

echo "Union: ", var_export($first + $second, true), "n";
echo "Merge: ", var_export(array_merge($first, $second), true), "n";

// array_push returns int, not an array:
array_push($first, $second);
echo "Push: ", var_export($first, true), "n";
</code></pre>
<p>The output:</p>
<pre>
Union: array (
  0 => 'doh',
  1 => 'ray',
  2 => 'me',
  3 => 'te',
  4 => 'do',
)
Merge: array (
  0 => 'doh',
  1 => 'ray',
  2 => 'me',
  3 => 'fah',
  4 => 'soh',
  5 => 'lah',
  6 => 'te',
  7 => 'do',
)
Push: array (
  0 => 'doh',
  1 => 'ray',
  2 => 'me',
  3 =>
  array (
    0 => 'fah',
    1 => 'soh',
    2 => 'lah',
    3 => 'te',
    4 => 'do',
  ),
)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://hexmen.com/blog/2008/11/concatenating-arrays-in-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
