<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Remove NULL values from PHP arrays with 1 line</title>
	<atom:link href="http://briancray.com/2009/04/25/remove-null-values-php-arrays/feed/" rel="self" type="application/rss+xml" />
	<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/</link>
	<description>User Experience Design, Web Development, and Internet Marketing</description>
	<lastBuildDate>Thu, 09 Sep 2010 10:23:41 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
	<atom:link rel="hub" href="http://superfeedr.com/hubbub" />
		<item>
		<title>By: Remove NULL values from PHP arrays with 1 line &#171; PHP Code Search</title>
		<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/#comment-32534</link>
		<dc:creator>Remove NULL values from PHP arrays with 1 line &#171; PHP Code Search</dc:creator>
		<pubDate>Wed, 01 Sep 2010 09:29:28 +0000</pubDate>
		<guid isPermaLink="false">http://briancray.com/?p=437#comment-32534</guid>
		<description>[...] Thanks to http://briancray.com/2009/04/25/remove-null-values-php-arrays/ [...]</description>
		<content:encoded><![CDATA[<p>[...] Thanks to http://briancray.com/2009/04/25/remove-null-values-php-arrays/ [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NXie</title>
		<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/#comment-32429</link>
		<dc:creator>NXie</dc:creator>
		<pubDate>Thu, 24 Jun 2010 02:10:17 +0000</pubDate>
		<guid isPermaLink="false">http://briancray.com/?p=437#comment-32429</guid>
		<description>Nice job. Exactly what I was looking for.</description>
		<content:encoded><![CDATA[<p>Nice job. Exactly what I was looking for.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Impossibly simple image randomizer with jQuery</title>
		<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/#comment-31637</link>
		<dc:creator>Impossibly simple image randomizer with jQuery</dc:creator>
		<pubDate>Mon, 04 Jan 2010 04:05:44 +0000</pubDate>
		<guid isPermaLink="false">http://briancray.com/?p=437#comment-31637</guid>
		<description>[...] or advertisment on each new pageview. I&#8217;m always looking for ways to simplify code [see 1, 2, 3], and naturally, I tried to do it [...]</description>
		<content:encoded><![CDATA[<p>[...] or advertisment on each new pageview. I&#8217;m always looking for ways to simplify code [see 1, 2, 3], and naturally, I tried to do it [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/#comment-26662</link>
		<dc:creator>David</dc:creator>
		<pubDate>Mon, 27 Jul 2009 08:38:28 +0000</pubDate>
		<guid isPermaLink="false">http://briancray.com/?p=437#comment-26662</guid>
		<description>is_scalar will work for Cometbus&#039; sample array.</description>
		<content:encoded><![CDATA[<p>is_scalar will work for Cometbus&#8217; sample array.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Cray</title>
		<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/#comment-1243</link>
		<dc:creator>Brian Cray</dc:creator>
		<pubDate>Mon, 27 Apr 2009 18:26:03 +0000</pubDate>
		<guid isPermaLink="false">http://briancray.com/?p=437#comment-1243</guid>
		<description>Cometbus:

You&#039;re right about that. I added my original code for this tutorial, which removes ONLY NULL values.</description>
		<content:encoded><![CDATA[<p>Cometbus:</p>
<p>You&#8217;re right about that. I added my original code for this tutorial, which removes ONLY NULL values.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cometbus</title>
		<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/#comment-1197</link>
		<dc:creator>Cometbus</dc:creator>
		<pubDate>Mon, 27 Apr 2009 08:31:18 +0000</pubDate>
		<guid isPermaLink="false">http://briancray.com/?p=437#comment-1197</guid>
		<description>I do not see any way to do this correctly without iterating each item and explicitly unsetting each null.  You could pass a unset null function to the array filter, but it is still more than one line.  Maybe a regex could get it to one line.

Currently, this method is dangerous, as it will remove a lot more than just nulls...

&lt;code&gt;$test_array = array(&#039;a&#039;, &#039;b&#039;, &#039;c&#039;, &#039;1&#039;, &#039;2&#039;, &#039;3&#039;, null, FALSE, 0, TRUE, 1, &#039;&#039;);

$new_array_without_nulls = array_filter($test_array);

print_r($test_array);
print_r($new_array_without_nulls);

Array
(
    [0] =&gt; a
    [1] =&gt; b
    [2] =&gt; c
    [3] =&gt; 1
    [4] =&gt; 2
    [5] =&gt; 3
    [6] =&gt; 
    [7] =&gt; 
    [8] =&gt; 0
    [9] =&gt; 1
    [10] =&gt; 1
    [11] =&gt; 
)
Array
(
    [0] =&gt; a
    [1] =&gt; b
    [2] =&gt; c
    [3] =&gt; 1
    [4] =&gt; 2
    [5] =&gt; 3
    [9] =&gt; 1
    [10] =&gt; 1
)
&lt;/code&gt;

As you can see, both false and empty strings were removed.  A lot of this has to do with php being a bit strange in what it calls a boolean/null/empty etc.

Not saying this is not a good thing, just that it could cause you unappreciable behavior.  Arrays are often used as a place to store boolean data, and this would clobber that data on the false side of it.</description>
		<content:encoded><![CDATA[<p>I do not see any way to do this correctly without iterating each item and explicitly unsetting each null.  You could pass a unset null function to the array filter, but it is still more than one line.  Maybe a regex could get it to one line.</p>
<p>Currently, this method is dangerous, as it will remove a lot more than just nulls&#8230;</p>
<p><code>$test_array = array('a', 'b', 'c', '1', '2', '3', null, FALSE, 0, TRUE, 1, '');</p>
<p>$new_array_without_nulls = array_filter($test_array);</p>
<p>print_r($test_array);<br />
print_r($new_array_without_nulls);</p>
<p>Array<br />
(<br />
    [0] =&gt; a<br />
    [1] =&gt; b<br />
    [2] =&gt; c<br />
    [3] =&gt; 1<br />
    [4] =&gt; 2<br />
    [5] =&gt; 3<br />
    [6] =&gt;<br />
    [7] =&gt;<br />
    [8] =&gt; 0<br />
    [9] =&gt; 1<br />
    [10] =&gt; 1<br />
    [11] =&gt;<br />
)<br />
Array<br />
(<br />
    [0] =&gt; a<br />
    [1] =&gt; b<br />
    [2] =&gt; c<br />
    [3] =&gt; 1<br />
    [4] =&gt; 2<br />
    [5] =&gt; 3<br />
    [9] =&gt; 1<br />
    [10] =&gt; 1<br />
)<br />
</code></p>
<p>As you can see, both false and empty strings were removed.  A lot of this has to do with php being a bit strange in what it calls a boolean/null/empty etc.</p>
<p>Not saying this is not a good thing, just that it could cause you unappreciable behavior.  Arrays are often used as a place to store boolean data, and this would clobber that data on the false side of it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Cray</title>
		<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/#comment-1137</link>
		<dc:creator>Brian Cray</dc:creator>
		<pubDate>Sun, 26 Apr 2009 04:40:34 +0000</pubDate>
		<guid isPermaLink="false">http://briancray.com/?p=437#comment-1137</guid>
		<description>Paul: Updated. Thanks so much for your valuable and obviously superior knowledge :)</description>
		<content:encoded><![CDATA[<p>Paul: Updated. Thanks so much for your valuable and obviously superior knowledge <img src='http://briancray.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Scott</title>
		<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/#comment-1136</link>
		<dc:creator>Paul Scott</dc:creator>
		<pubDate>Sun, 26 Apr 2009 04:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://briancray.com/?p=437#comment-1136</guid>
		<description>As far as I remember, you don&#039;t need the 2nd arg to array_filter to remove NULL values. just $array_without_nulls = array_filter($array_with_nulls); will do</description>
		<content:encoded><![CDATA[<p>As far as I remember, you don&#8217;t need the 2nd arg to array_filter to remove NULL values. just $array_without_nulls = array_filter($array_with_nulls); will do</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Drew Douglass</title>
		<link>http://briancray.com/2009/04/25/remove-null-values-php-arrays/#comment-1113</link>
		<dc:creator>Drew Douglass</dc:creator>
		<pubDate>Sat, 25 Apr 2009 17:28:07 +0000</pubDate>
		<guid isPermaLink="false">http://briancray.com/?p=437#comment-1113</guid>
		<description>Nice stuff Brian, I&#039;m assuming array_map() would work similarly to array_filter() in this situation?

I&#039;m a big fan of these quick one liners, keep them coming buddy!</description>
		<content:encoded><![CDATA[<p>Nice stuff Brian, I&#8217;m assuming array_map() would work similarly to array_filter() in this situation?</p>
<p>I&#8217;m a big fan of these quick one liners, keep them coming buddy!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (enhanced)
Database Caching using disk
Object Caching 264/268 objects using disk

Served from: briancray.com @ 2010-09-09 10:24:29 -->