<?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>Wed, 10 Mar 2010 04: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>asort()</title>
		<link>http://phpnightly.com/2010/03/10/asort-2/</link>
		<comments>http://phpnightly.com/2010/03/10/asort-2/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 04:00:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1795</guid>
		<description><![CDATA[Sorts an array by value lowest to highest while maintaining the associated keys (both string and numeric). The array itself is affected; this does not return a new array.]]></description>
			<content:encoded><![CDATA[<p>Sort an array by its values from lowest to highest just like sort(). Only true or false is returned (success or failure). This function alters the input array itself.</p>
<p>The difference between this and sort() is that asort() keeps the keys intact. This is useful for associative arrays, but it keeps the numeric keys as well as string keys.</p>
<p>To sort from highest to lowest, see <a href="http://php.net/arsort">arsort()</a> which works the same as this function.</p>
<p>Optional flags can be used as the second parameter. SORT_REGULAR is the default.</p>
<table style="clear: both;">
<tr>
<td>SORT_REGULAR</td>
<td>Compare items normally (don&#8217;t change types)</td>
</tr>
<tr>
<td>SORT_NUMERIC</td>
<td>Compare items numerically</td>
</tr>
<tr>
<td>SORT_STRING</td>
<td>Compare items as strings</td>
</tr>
<tr>
<td>SORT_LOCALE_STRING</td>
<td>Compare items as strings, based on the current locale.</td>
</tr>
</table>
<p>If the values are of mixed types, you may not get the result you expect in some cases.</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;">'eggplant'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'banana'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'dandelion'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'carrot'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">asort</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 (
  2 =&gt; 'apple',
  1 =&gt; 'banana',
  4 =&gt; 'carrot',
  3 =&gt; 'dandelion',
  0 =&gt; 'eggplant'
)
*/</span>
&nbsp;
<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;">'test'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'eggplant'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'banana'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'sample'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">17</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dandelion'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'carrot'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">asort</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 (
  'sample' =&gt; 'apple',
  0 =&gt; 'banana',
  18 =&gt; 'carrot',
  17 =&gt; 'dandelion',
  'test' =&gt; 'eggplant'
)
*/</span>
&nbsp;
<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;">'25'</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">43</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">8004</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'8004'</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;">52</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">asort</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 (
  6 =&gt; -52,
  5 =&gt; 0,
  3 =&gt; 3,
  0 =&gt; '25',
  1 =&gt; 43,
  4 =&gt; '8004',
  2 =&gt; 8004
)
*/</span>
&nbsp;
<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;">'25'</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">43</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">8004</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'8004'</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;">52</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">asort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #339933;">,</span> SORT_STRING<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  6 =&gt; -52,
  5 =&gt; 0,
  0 =&gt; '25',
  3 =&gt; 3,
  1 =&gt; 43,
  2 =&gt; 8004,
  4 =&gt; '8004'
)
*/</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/asort">asort()</a><br />
Originally posted <a href="http://phpnightly.com/2009/03/10/">2009-03-10</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/03/10/asort-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>sort()</title>
		<link>http://phpnightly.com/2010/03/09/sort-2/</link>
		<comments>http://phpnightly.com/2010/03/09/sort-2/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 05:00:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1794</guid>
		<description><![CDATA[Sorts an array by value lowest to highest. The array itself is re-indexed; this does not return a new array.]]></description>
			<content:encoded><![CDATA[<p>Sort an array by its values from lowest to highest. All of the keys are lost as it is re-indexed as a numerically indexed array. Only true or false is returned (success or failure). This function alters the input array itself.</p>
<p>To sort from highest to lowest, see <a href="http://php.net/rsort">rsort()</a> which works the same as this function.</p>
<p>Optional flags can be used as the second parameter. SORT_REGULAR is the default.</p>
<table style="clear: both;">
<tr>
<td>SORT_REGULAR</td>
<td>Compare items normally (don&#8217;t change types)</td>
</tr>
<tr>
<td>SORT_NUMERIC</td>
<td>Compare items numerically</td>
</tr>
<tr>
<td>SORT_STRING</td>
<td>Compare items as strings</td>
</tr>
<tr>
<td>SORT_LOCALE_STRING</td>
<td>Compare items as strings, based on the current locale.</td>
</tr>
</table>
<p>If the values are of mixed types, you may not get the result you expect in some cases.</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;">'eggplant'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'banana'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'dandelion'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'carrot'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sort</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; 'apple',
  1 =&gt; 'banana',
  2 =&gt; 'carrot',
  3 =&gt; 'dandelion',
  4 =&gt; 'eggplant'
)
*/</span>
&nbsp;
<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;">'test'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'eggplant'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'banana'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'sample'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'apple'</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">17</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dandelion'</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'carrot'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sort</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; 'apple',
  1 =&gt; 'banana',
  2 =&gt; 'carrot',
  3 =&gt; 'dandelion',
  4 =&gt; 'eggplant'
)
*/</span>
&nbsp;
<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;">'25'</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">43</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">8004</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'8004'</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;">52</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sort</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; -52,
  1 =&gt; 0,
  2 =&gt; 3,
  3 =&gt; '25',
  4 =&gt; 43,
  5 =&gt; '8004',
  6 =&gt; 8004
)
*/</span>
&nbsp;
<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;">'25'</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">43</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">8004</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'8004'</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;">52</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #339933;">,</span> SORT_STRING<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*
array (
  0 =&gt; -52,
  1 =&gt; 0,
  2 =&gt; '25',
  3 =&gt; 3,
  4 =&gt; 43,
  5 =&gt; 8004,
  6 =&gt; '8004'
)
*/</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/sort">sort()</a><br />
Originally posted <a href="http://phpnightly.com/2009/03/09/">2009-03-09</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/03/09/sort-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>array_sum()</title>
		<link>http://phpnightly.com/2010/03/08/array_sum-2/</link>
		<comments>http://phpnightly.com/2010/03/08/array_sum-2/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 20:32:01 +0000</pubDate>
		<dc:creator>php|nightly</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://phpnightly.com/?p=1793</guid>
		<description><![CDATA[Sums up the values of an array. Values will be converted to int or float for calculation (the array will not be changed). Nested arrays are ignored (counted as zero).]]></description>
			<content:encoded><![CDATA[<p>This function will add up the values of an array. Values will be converted to integer or float for calculation only. The array will remain unchanged.</p>
<p>Nested arrays will be ignored regardless of their values. Consider them zero to this function.</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: #cc66cc;">2</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sum</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_sum</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;">// 17</span>
&nbsp;
&nbsp;
<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: #cc66cc;">2</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">6</span><span style="color: #339933;">,</span>
             <span style="color: #0000ff;">'5'</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>
&nbsp;
<span style="color: #000088;">$sum</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_sum</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;">// 18</span>
&nbsp;
&nbsp;
<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: #cc66cc;">2</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
             <span style="color:#800080;">3.7</span><span style="color: #339933;">,</span>
             <span style="color: #339933;">-</span><span style="color: #cc66cc;">82</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sum</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_sum</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;">// -72.3</span>
&nbsp;
&nbsp;
<span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">,</span>
           <span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$y</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'12Monkeys'</span><span style="color: #339933;">;</span>
<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: #cc66cc;">2</span><span style="color: #339933;">,</span>
             <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
             <span style="color: #000088;">$x</span><span style="color: #339933;">,</span>
             <span style="color: #000088;">$y</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$sum</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_sum</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;">// 18</span></pre></div></div>

<div class="manlink">
See the manual entry for <a href="http://php.net/array_sum">array_sum()</a><br />
Originally posted <a href="http://phpnightly.com/2009/03/07/">2009-03-07</a></div>
]]></content:encoded>
			<wfw:commentRss>http://phpnightly.com/2010/03/08/array_sum-2/feed/</wfw:commentRss>
		</item>
		<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>
	</channel>
</rss>
