<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>php|nightly</title>
	
	<link>http://phpnightly.com</link>
	<description>Your page-a-day PHP</description>
	<pubDate>Sat, 06 Mar 2010 05:00:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="phpnightly" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://phpnightly.com/feed" /><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Fphpnightly.com%2Ffeed" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Fphpnightly.com%2Ffeed" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Fphpnightly.com%2Ffeed" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.bloglines.com/sub/http://phpnightly.com/feed" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Fphpnightly.com%2Ffeed" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://fusion.google.com/add?feedurl=http%3A%2F%2Fphpnightly.com%2Ffeed" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Fphpnightly.com%2Ffeed" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
		<title>array_merge()</title>
		<link>http://phpnightly.com/2010/03/06/array_merge-2/</link>
		<comments>http://phpnightly.com/2010/03/06/array_merge-2/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 05:00:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1792</guid>
		<description><![CDATA[Like merging in traffic, bring together the values of two or more arrays. Numeric keys will be re-indexed. Other keys will remain but will be overwritten if a duplicate is encountered.]]></description>
			<content:encoded><![CDATA[<p>Combine the values of two or more arrays into a new array. Values will be appended onto the end with numeric keys being re-indexed as it goes. Should a duplicate non-numeric key be found, the previous value is overwritten.</p>
<p>You might think of this as adding arrays together, which is fine, but you can actually use + with arrays. More about that after a few examples.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'e'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$a2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'o'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'i'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'u'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 'a',
  1 =&gt; 'b',
  2 =&gt; 'c',
  3 =&gt; 'd',
  4 =&gt; 'e',
  5 =&gt; 'p',
  6 =&gt; 'o',
  7 =&gt; 'i',
  8 =&gt; 'u'
)
*/</span>
&nbsp;
<span style="color: #000088;">$a1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'this'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'e'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$a2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'that'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'o'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'i'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'u'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 'a',
  1 =&gt; 'b',
  'this' =&gt; 'c',
  2 =&gt; 'd',
  3 =&gt; 'e',
  4 =&gt; 'p',
  'that' =&gt; 'o',
  5 =&gt; 'i',
  6 =&gt; 'u'
)
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// even the first array is re-indexed</span>
<span style="color: #666666; font-style: italic;">// 'this' value is overwritten</span>
<span style="color: #000088;">$a1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'b'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'this'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'c'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'d'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'e'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$a2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">17</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'p'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'this'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'o'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'i'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'u'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 'a',
  1 =&gt; 'b',
  'this' =&gt; 'o',
  2 =&gt; 'd',
  3 =&gt; 'e',
  4 =&gt; 'p',
  5 =&gt; 'i',
  6 =&gt; 'u'
)
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// if only one array is given, it is just re-indexed</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 'a',
  1 =&gt; 'b',
  'this' =&gt; 'c',
  2 =&gt; 'd',
  3 =&gt; 'e'
)
*/</span></pre></div></div>

<p>Remember, this function will accept more than two arrays.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'D'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a3</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2001</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'oddity'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a4</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'k'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a3</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 3,
  1 =&gt; 4,
  2 =&gt; 5,
  3 =&gt; 6,
  4 =&gt; 7,
  5 =&gt; 'A',
  6 =&gt; 'B',
  7 =&gt; 'C',
  8 =&gt; 'D',
  9 =&gt; 'oddity',
  10 =&gt; 'i',
  11 =&gt; 'j',
  12 =&gt; 'k'
)
*/</span></pre></div></div>

<p>Using + to merge arrays together acts differently. The keys are not re-indexed, and values are not overwritten. For duplicate keys (even numeric ones) the previous value stands and the other is ignored.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'C'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'D'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a3</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'m'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">13</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'n'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">14</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$a4</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">17</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Q'</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">18</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'R'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$a1</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$a2</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$a3</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$a4</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 'a',
  1 =&gt; 'b',
  2 =&gt; 'C',
  3 =&gt; 'D',
  'm' =&gt; 13,
  'n' =&gt; 14,
  17 =&gt; 'Q',
  18 =&gt; 'R'
)
*/</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/array_merge">array_merge()</a><br />
Originally posted <a href="http://phpnightly.com/2009/03/06/">2009-03-06</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/03/06/array_merge-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>array_combine()</title>
		<link>http://phpnightly.com/2010/03/05/array_combine-2/</link>
		<comments>http://phpnightly.com/2010/03/05/array_combine-2/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 05:00:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1791</guid>
		<description><![CDATA[Use the values of two arrays to form a new array. The values of one will be used as the keys. The value of the second will be used as the new array's values. The two arrays must have the same number of elements.]]></description>
			<content:encoded><![CDATA[<p>&#8220;You&#8217;ve got your values with my keys!&#8221;<br />
  &#8220;You&#8217;ve got your keys with my values!&#8221;<br />
Mmmm&#8230;</p>
<p>Use the values of one array as the keys, and the values of another array as the values, and get a brand new array from the combination.</p>
<p>The stipulations are:</p>
<ul>
<li>The two arrays must have the same number of elements</li>
<li>The keys will be converted to string if necessary</li>
<li>Keys of an integer in string format will become a numeric key</li>
<li>Values will be overwritten on duplicate keys</li>
</ul>
<p>As you&#8217;ll see here, the keys of your original arrays do not matter. Only the values are combined to create the new array.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'two'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'three'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'four'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'the'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'five'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'end'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$a2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'banana'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'c'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'carrot'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'d'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dandelion'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'e'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'eggplant'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_combine</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  1 =&gt; 'apple',
  2 =&gt; 'banana',
  300 =&gt; 'carrot',
  'the' =&gt; 'dandelion',
  'end' =&gt; 'eggplant'
)
*/</span></pre></div></div>

<p>An example of overwriting duplicate keys. Note that the resulting array has only four elements.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'one'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'two'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'three'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'four'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'the'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'five'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$a2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'banana'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'c'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'carrot'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'d'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dandelion'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'e'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'eggplant'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_combine</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  1 =&gt; 'apple',
  2 =&gt; 'banana',
  300 =&gt; 'eggplant',
  'the' =&gt; 'dandelion'
)
*/</span></pre></div></div>

<p>For the keys, false will become the empty string, true will become one (1), integers in quotes will become numeric (even negative), floats will become strings.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span>
            <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
            <span style="color: #339933;">-</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'-6'</span><span style="color: #339933;">,</span>
            <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'two words'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'@#$'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'4.5'</span><span style="color: #339933;">,</span>
            <span style="color:#800080;">3.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$a2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">7</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span>
            <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_combine</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$a2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  'a' =&gt; 1,
  '' =&gt; 2,
  0 =&gt; 3,
  -4 =&gt; 4,
  -6 =&gt; 5,
  1 =&gt; 6,
  'two words' =&gt; 7,
  '@#$' =&gt; 8,
  '4.5' =&gt; 9,
  '3.5' =&gt; 0
)
*/</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/array_combine">array_combine()</a><br />
Originally posted <a href="http://phpnightly.com/2009/03/05/">2009-03-05</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/03/05/array_combine-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>array_fill_keys()</title>
		<link>http://phpnightly.com/2010/03/04/array_fill_keys-2/</link>
		<comments>http://phpnightly.com/2010/03/04/array_fill_keys-2/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 05:00:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1790</guid>
		<description><![CDATA[Creates an array with the keys you specify and initializes each element with the value of your choice. Each element will contain the same value. Like array_fill() but you specify the keys.]]></description>
			<content:encoded><![CDATA[<p>This function acts similar to array_fill() but is different in that you specify the keys to use instead of simply creating a numerically keyed array.</p>
<p>Since you are suppling the keys, you do not need to tell it how many elements to make (it will use all of the keys) and you do not need to tell it where to start; just give it the list of keys and the value to use for each one and off it goes.</p>
<p>As an example, here&#8217;s how those two functions can produce the same output.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">17</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Q'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// start with key of 5, make 17 elements</span>
<span style="color: #000088;">$arr2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill_keys</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">22</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Q'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// for keys, use an array of 5-22 (has 17 elements)</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'another'</span><span style="color: #339933;">,</span>
              <span style="color: #cc66cc;">42</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'this_one'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keys</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'X'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  'first' =&gt; 'X',
  'another' =&gt; 'X',
  42 =&gt; 'X',
  'this_one' =&gt; 'X'
)
*/</span></pre></div></div>

<p>In your array of keys to use, a string which is an integer value will be converted to that integer value (even negative numbers).  Boolean false will become an empty string, true will become integer one (1). Duplicate keys will be ignored.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'another'</span><span style="color: #339933;">,</span>
              <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
              <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
              <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'87'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'-4'</span><span style="color: #339933;">,</span>
              <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'42.5'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'this_one'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$keys</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'X'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  'first' =&gt; 'X',
  'another' =&gt; 'X',
  0 =&gt; 'X',
  '' =&gt; 'X',
  1 =&gt; 'X',
  87 =&gt; 'X',
  -4 =&gt; 'X',
  '42.5' =&gt; 'X',
  'this_one' =&gt; 'X'
)
*/</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/array_fill_keys">array_fill_keys()</a><br />
Originally posted <a href="http://phpnightly.com/2009/03/04/">2009-03-04</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/03/04/array_fill_keys-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>array_fill()</title>
		<link>http://phpnightly.com/2010/03/03/array_fill-2/</link>
		<comments>http://phpnightly.com/2010/03/03/array_fill-2/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 05:00:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1789</guid>
		<description><![CDATA[Create a numerically indexed array starting at the index of your choice, with each element having the same value which you specify. Of course, you also specify the number of elements the array will have.]]></description>
			<content:encoded><![CDATA[<p>This function will create an array and initialize the elements with the value of your choosing. The resulting array will be numerically indexed.</p>
<p>You specify the starting index, the number of elements the array will contain, and the value to be used for each of those elements.</p>
<p>This can be useful for initializing an array before merging other data with it so that each key will have a value associated with it instead of ending up with &#8220;holes&#8221; in the array by having some not being set.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'monkey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  4 =&gt; 'monkey',
  5 =&gt; 'monkey',
  6 =&gt; 'monkey'
)
*/</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">17</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 17,
  1 =&gt; 17,
  2 =&gt; 17,
  3 =&gt; 17,
  4 =&gt; 17
)
*/</span></pre></div></div>

<p>The value may be any type that could be placed in an array.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</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: #666666; font-style: italic;">/*
array (
  8 =&gt; false,
  9 =&gt; false,
  10 =&gt; false
)
*/</span>
&nbsp;
<span style="color: #000088;">$val</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'banana'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  3 =&gt; 
  array (
    0 =&gt; 'apple',
    1 =&gt; 'banana'
  ),
  4 =&gt; 
  array (
    0 =&gt; 'apple',
    1 =&gt; 'banana'
  )
)
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// a quick way to set up a multidimensional &quot;grid&quot; array</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #990000;">array_fill</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Q'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// a 5x5 array with each element initialized to Q</span></pre></div></div>

<p>The second parameter will be converted to an integer (decimals are truncated). If it is less than one, however, a warning will be given and false is returned. Keep in mind again how types are converted to integers.</p>
<p>If the first parameter is negative, the first element will have that negative key, but the second element will step to zero, then one, etc. This is the normal functionality of arrays.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'2x'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'monkey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 'monkey',
  1 =&gt; 'monkey'
)
*/</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_fill</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">17</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'X'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  -17 =&gt; 'X',
  0 =&gt; 'X',
  1 =&gt; 'X',
  2 =&gt; 'X'
)
*/</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/array_fill">array_fill()</a><br />
Originally posted <a href="http://phpnightly.com/2009/03/03/">2009-03-03</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/03/03/array_fill-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>range()</title>
		<link>http://phpnightly.com/2010/03/02/range-2/</link>
		<comments>http://phpnightly.com/2010/03/02/range-2/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 05:00:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1788</guid>
		<description><![CDATA[Creates an array filled with values of a range from your starting point to your end point. You can also specify a step; the default step is one.]]></description>
			<content:encoded><![CDATA[<p>Instantly create an array full of values in a range of your choice. For example, all the numbers five through twenty, or the letters B through N, or maybe just the odd numbers zero through fifty.</p>
<p>You specify the starting point, the ending point, and optionally the step (defaults to one). If the start is greater than the end, the array will be filled &#8220;backwards&#8221;.</p>
<p>Only the first character of the strings will be used when creating a range of characters. Any other characters of the string will be ignored.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</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;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// array(1, 2, 3, 4, 5, 6, 7, 8)</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</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: #666666; font-style: italic;">// array(8, 7, 6, 5, 4, 3, 2, 1)</span>
<span style="color: #000088;">$arr</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;">8</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// array(1, 3, 5, 7)</span>
<span style="color: #000088;">$arr</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;">8</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// array(1, 6)</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'q'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// array('q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y')</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'q'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'m'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">// array('q', 'p', 'o', 'n', 'm')</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'q'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'y'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// array('q', 's', 'u', 'w', 'y')</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'q'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'y'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// array('q', 'v')</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// this function appears to take the</span>
<span style="color: #666666; font-style: italic;">// absolute value of the step parameter</span>
<span style="color: #000088;">$arr</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;">8</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// array(1, 3, 5, 7)</span></pre></div></div>

<p>Take care mixing integers and strings. The string will first be converted to a numeric value. Also, the step need not be a whole number. However, if the step is not a whole number, any strings used will be converted to numeric.</p>
<p>If the string is converted to a numeric value, the &#8220;only the first character&#8221; rule is out. That rule is applied <em>after</em> any conversion.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// array(1, 2, 3, 4, 5, 6, 7, 8)</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'x'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// array(2, 1, 0)</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'5x'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// array(2, 3, 4, 5)</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color:#800080;">.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;">// array(2, 2.5, 3, 3.5, 4)</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">3.14</span><span style="color: #339933;">,</span> <span style="color:#800080;">5.2</span><span style="color: #339933;">,</span> <span style="color:#800080;">.3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// array(3.14, 3.44, 3.74, 4.04, 4.34, 4.64, 4.94, 5.24)</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'g'</span><span style="color: #339933;">,</span> <span style="color:#800080;">.5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// array(0);</span>
&nbsp;
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">range</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'28'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'33'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// array(28, 29, 30, 31, 32, 33)</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$nums</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;">69</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">shuffle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$nums</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Your winning lottery numbers are:
<span style="color: #006699; font-weight: bold;">{$nums[0]}</span> <span style="color: #006699; font-weight: bold;">{$nums[1]}</span> <span style="color: #006699; font-weight: bold;">{$nums[2]}</span> <span style="color: #006699; font-weight: bold;">{$nums[3]}</span> <span style="color: #006699; font-weight: bold;">{$nums[4]}</span> <span style="color: #006699; font-weight: bold;">{$nums[5]}</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<div class="manlink">Originally posted <a href="http://phpnightly.com/2009/03/02/">2009-03-02</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/03/02/range-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHPClasses</title>
		<link>http://phpnightly.com/2010/03/01/phpclasses-2/</link>
		<comments>http://phpnightly.com/2010/03/01/phpclasses-2/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 05:00:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1787</guid>
		<description><![CDATA[Open source resource for object oriented PHP code. Community based. Upload and share your creations.

Monthly voting for the "Programming Innovation" award where authors could win valuable prizes.]]></description>
			<content:encoded><![CDATA[<p><a href="http://phpclasses.org">PHPClasses.org</a> is a resource for object oriented PHP code. The site itself is full of advertisements and can be difficult to navigate, but with over 2300 authors contributing over 4400 files, it can be a great place to find ready-to-go code or maybe just some inspiration.</p>
<p>It&#8217;s all community based. Anyone can contribute, though there is a review process. It&#8217;s a good way to get your code seen and get your name out if that&#8217;s what you&#8217;re after. Some people have elected to be notified on each new approved contribution. You could have thousands of people looking at and possibly using your code!</p>
<p>Not all classes at the site will be available for you to use, however. It depends on the license attached. At the time of this writing, here are the licenses listed on the contribution page.</p>
<ul>
<li>Artistic License</li>
<li>BSD License</li>
<li>GNU Free Documentation License (FDL)</li>
<li>GNU General Public License (GPL)</li>
<li>GNU Lesser General Public License (LGPL)</li>
<li>MIT/X Consortium License</li>
<li>Python License</li>
<li>Q Public License (QPL)</li>
<li>Free For Educational Use</li>
<li>Free For Non-Commercial Use</li>
<li>Free To Use But Restricted</li>
<li>Freely Distributable</li>
<li>Freeware</li>
<li>Proprietary License</li>
<li>Proprietary License with Source</li>
<li>Public Domain</li>
<li>Shareware</li>
<li>The PHP License</li>
<li>Other (custom)</li>
</ul>
<p>So, if you&#8217;re planning to piece together some commercial software, make sure the license allows for that.</p>
<p>Are there similar resources out there? Which are your favorites? Let us know in the comments here.
<div class="manlink">Originally posted <a href="http://phpnightly.com/2009/02/28/">2009-02-28</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/03/01/phpclasses-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>array_keys()</title>
		<link>http://phpnightly.com/2010/02/27/array_keys-2/</link>
		<comments>http://phpnightly.com/2010/02/27/array_keys-2/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 15:24:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1786</guid>
		<description><![CDATA[Returns an array whose values are the keys of the input array. Optionally, search for a value in the input array and return only those keys with corresponding values.]]></description>
			<content:encoded><![CDATA[<p>Give this function an array and you&#8217;ll get back an array, the values of which will be the keys of the original array.</p>
<p>As a bonus, you can request to get only the keys which correspond to a certain value. Specify the value (a single value only, though it may be of any type) in the second parameter. Set the third parameter to true if you want to be strict in searching against type. (see the <a href="http://phpnightly.com/2009/01/05/">entry on == vs. ===</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'elephant'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'banana'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'c'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'carrot'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'fly'</span><span style="color: #339933;">,</span>
             <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'z'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'zucchini'</span><span style="color: #339933;">,</span>
                   <span style="color: #0000ff;">'y'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yarrow'</span><span style="color: #339933;">,</span>
                   <span style="color: #0000ff;">'platypus'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'gnat'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$new_arr1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 0,
  1 =&gt; 'a',
  2 =&gt; 'b',
  3 =&gt; 'c',
  4 =&gt; 1,
  5 =&gt; 2,
  6 =&gt; 3
)
*/</span>
&nbsp;
<span style="color: #000088;">$new_arr2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'banana'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 'b'
)
*/</span>
&nbsp;
<span style="color: #000088;">$search</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'banana'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'elephant'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'gnat'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$new_arr3</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array ()
*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Search must be a single value. In this case it was looking for</span>
<span style="color: #666666; font-style: italic;">// a value matching that array which does not exist.</span>
<span style="color: #666666; font-style: italic;">// Compare the above with the following.</span>
&nbsp;
<span style="color: #000088;">$search</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'z'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'zucchini'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'y'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yarrow'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'platypus'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$new_arr4</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 2
)
*/</span></pre></div></div>

<p>When using the search feature, be careful of types. That&#8217;s what the third parameter is for. Set it to true to match the value and type.</p>
<p>Here you&#8217;ll see an example of returning multiple keys, followed by examples of searching through different types.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pumpkin'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'acorn'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'spaghetti'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'butternut'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'acorn'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$new_arr1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'acorn'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 1,
  1 =&gt; 4
)
*/</span>
&nbsp;
<span style="color: #000088;">$arr2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">17</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">255</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
             <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$new_arr2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 2,
  1 =&gt; 3,
  2 =&gt; 4,
  3 =&gt; 5
)
*/</span>
&nbsp;
<span style="color: #000088;">$new_arr3</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr2</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: #666666; font-style: italic;">/*
array (
  0 =&gt; 2,
  1 =&gt; 4,
  2 =&gt; 5
)
*/</span>
&nbsp;
<span style="color: #000088;">$new_arr4</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr2</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 2
)
*/</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/array_keys">array_keys()</a><br />
Originally posted <a href="http://phpnightly.com/2009/02/27/">2009-02-27</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/02/27/array_keys-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>array_values()</title>
		<link>http://phpnightly.com/2010/02/26/array_values-2/</link>
		<comments>http://phpnightly.com/2010/02/26/array_values-2/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 05:00:37 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1778</guid>
		<description><![CDATA[Converts an array into a numerically indexed array (starting at zero). The original array is left untouched (a new array is returned). Nested arrays are not re-indexed.]]></description>
			<content:encoded><![CDATA[<p>This function will take an array and give you back an array with all the same values but re-indexed numerically, starting at zero. Think of it somewhat as straightening a deck of cards. All the cards are still there but now they&#8217;re all presented in a nice, neat stack.</p>
<p>The keys of your input array will not be used. Any nested arrays will not be re-indexed, however. Those keys will remain.</p>
<p>The array you pass to this function will not be altered. A new array is created and returned to you.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'elephant'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'a'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'b'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'banana'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'c'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'carrot'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'fly'</span><span style="color: #339933;">,</span>
             <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'z'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'zucchini'</span><span style="color: #339933;">,</span>
                   <span style="color: #0000ff;">'y'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yarrow'</span><span style="color: #339933;">,</span>
                   <span style="color: #0000ff;">'platypus'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'gnat'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$new_arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_values</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; 'elephant',
  1 =&gt; 'apple',
  2 =&gt; 'banana',
  3 =&gt; 'carrot',
  4 =&gt; 'fly',
  5 =&gt; array (
         'z' =&gt; 'zucchini',
         'y' =&gt; 'yarrow',
          0  =&gt; 'platypus',
       ),
  6 =&gt; 'gnat'
)
*/</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/array_values">array_values()</a><br />
Originally posted <a href="http://phpnightly.com/2009/02/26/">2009-02-26</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/02/26/array_values-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Optional Closing Tag</title>
		<link>http://phpnightly.com/2010/02/25/the-optional-closing-tag/</link>
		<comments>http://phpnightly.com/2010/02/25/the-optional-closing-tag/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 14:09:50 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1775</guid>
		<description><![CDATA[Should the closing PHP tag ?> be used at the end of a PHP file? This question was posed to the PHP community. There are arguments both for and against putting it in. See the poll results...]]></description>
			<content:encoded><![CDATA[<p>You know that a block of PHP code begins with &lt;?php and ends with ?> and anything outside of that will be sent as output. What you may or may not know is that the closing tag is optional at the end of a file.</p>
<p>So should you include this closing tag in your PHP files? That question was put out to the PHP community and here are the latest results:</p>
<p><script src="http://twtpoll.com/js/badge.js" type="text/javascript"></script><br />
<script src="http://twtpoll.com/badge/r/?twt=7rdp3r&#038;s=200" type="text/javascript"></script></p>
<h3>Arguments For NO</h3>
<p>Sure, the language is full of conveniences but what good is that bit of information? Leaving off the final closing PHP tag could have saved many hours of confusion for a number of people.</p>
<p>Have you ever came upon a &#8220;headers already sent&#8221; message and had no idea why? This comes up constantly in forums and lists and the solution is almost always to remove any whitespace before &lt;?php or after ?>. This whitespace issue is the number one (possibly only) reason to argue the possition of leaving off the final closing tag.</p>
<p>Unintended whitespace sent as output can lead not only to issues with sending headers, but also could introduce errors in other types of output such as XML or images.</p>
<p>Here&#8217;s an example of how this whitespace can be introduced into a file. Line numbers are included in these examples.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">--index.php--
1  <span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #cc66cc;">2</span>  <span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'inc.php'</span><span style="color: #339933;">;</span>
<span style="color: #cc66cc;">3</span>  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://phpnightly.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #cc66cc;">4</span>  <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #cc66cc;">5</span>  <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
--inc.php--
1  <span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #cc66cc;">2</span>  <span style="color: #666666; font-style: italic;">// some code here, maybe a hit counter</span>
<span style="color: #cc66cc;">3</span>  <span style="color: #666666; font-style: italic;">// this file isn't meant to output anything</span>
<span style="color: #cc66cc;">4</span>  <span style="color: #000000; font-weight: bold;">?&gt;</span>
5
6</pre></div></div>

<p>Running index.php will produce something like</p>
<blockquote><p>Warning: Cannot modify header information - headers already sent by (output started at \public_html\inc.php:6) in \public_html\index.php on line 3</p></blockquote>
<p>The closing tag can have a single new line after it without causing any problems. But a new line, space, tab, anything after that will be sent as output and can cause that warning message.</p>
<h3>Arguments For YES</h3>
<p>Why then, given this information that it could ruin a script, would you want to use it?</p>
<ol>
<li>It&#8217;s a clean and definite finish to the script</li>
<li>Leaving it off is just lazy. You should be sure there isn&#8217;t whitespace there</li>
<li>Every tag, brace, parenthesis, etc. needs a partner</li>
</ol>
<p>The manual states that <a href="http://php.net/manual/language.basic-syntax.instruction-separation.php">it is optional</a>. The Zend Framework coding standard (and others) says that it <em>must</em> be left off.</p>
<p>If you really aren&#8217;t concerned about the whitespace issue, it pretty much comes down to personal preference. Or whatever the boss says, of course.</p>
<p>Personally, I&#8217;ve come to prefer leaving it out. Potential issues are avoided and I don&#8217;t see a benefit to having it in there if there&#8217;s no output at the end.</p>
<div class="manlink">
Originally posted <a href="http://phpnightly.com/2009/02/25/">2009-02-25</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/02/25/the-optional-closing-tag/feed/</wfw:commentRss>
		</item>
		<item>
		<title>parse_str()</title>
		<link>http://phpnightly.com/2010/02/24/parse_str-2/</link>
		<comments>http://phpnightly.com/2010/02/24/parse_str-2/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 05:00:41 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/2010/02/24/parse_str-2/</guid>
		<description><![CDATA[Parses a string as if it were a query string. Puts the variables into the current scope [like extract()], or into an array named as the second parameter.]]></description>
			<content:encoded><![CDATA[<p>Deconstructs a URL query string parsing out the variable/value pairs. The array named as the second parameter will hold all the info. If the second parameter is not present, the variables will be put into the current scope (see <a href="http://phpnightly.com/2009/01/13/">extract</a>).</p>
<p>This function is the counterpart of <a href="http://phpnightly.com/2009/02/23">http_build_query()</a>.</p>
<p>I advise you to always include the second parameter to avoid overwriting data and to ensure you always know where your data originated from.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'monkey'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a=zebra&amp;b=yak&amp;c=Xavier&amp;0=litmus&amp;1=test&amp;d=whale'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
Equivalent to doing the following:
$a = 'zebra';
$b = 'yak';
$c = 'Xavier';
$0 = 'litmus';
$1 = 'test';
$d = 'whale';
&nbsp;
An error would be thrown if you tried to create the variables $0 and $1
but no error would occur parse_str, though you wouldn't be able to
retrieve the values of $0 or $1 here.
&nbsp;
$a would now hold the value &quot;zebra&quot;.
*/</span>
&nbsp;
<span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'a=zebra&amp;b=yak&amp;c=Xavier&amp;0=litmus&amp;1=test&amp;d=whale'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">parse_str</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span> <span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
$arr is now:
array (
  'a' =&gt; 'zebra',
  'b' =&gt; 'yak',
  'c' =&gt; 'Xavier',
  0   =&gt; 'litmus',
  1   =&gt; 'test',
  'd' =&gt; 'whale'
)
&nbsp;
Here, you could be able to access all values such as $arr[0] and $arr[1].
*/</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/parse_str">parse_str()</a><br />
Originally posted <a href="http://phpnightly.com/2009/02/24/">2009-02-24</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/02/24/parse_str-2/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
