<?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/"
	xmlns:series="http://unfoldingneurons.com/"
		>
<channel>
	<title>Comments on: Searching Arrays for Values</title>
	<atom:link href="http://www.brandonsavage.net/searching-arrays-for-values/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandonsavage.net/searching-arrays-for-values/</link>
	<description>The personal blog of Brandon Savage. Contains entries of a personal and professional nature focusing on PHP, Apple, LAMP, MySQL and Washington, DC.</description>
	<lastBuildDate>Thu, 29 Jul 2010 11:09:38 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Rory</title>
		<link>http://www.brandonsavage.net/searching-arrays-for-values/#comment-599</link>
		<dc:creator>Rory</dc:creator>
		<pubDate>Tue, 14 Jul 2009 01:18:50 +0000</pubDate>
		<guid isPermaLink="false">http://dev.brandonsavage.net/?p=105#comment-599</guid>
		<description>This post is old but people never make use of all the great built-in array functions:

$exclude = array(&#039;submit&#039; =&gt; true, &#039;go&#039; =&gt; true);

$valid = array_diff_key($_POST, $exclude);</description>
		<content:encoded><![CDATA[<p>This post is old but people never make use of all the great built-in array functions:</p>
<p>$exclude = array(&#8216;submit&#8217; =&gt; true, &#8216;go&#8217; =&gt; true);</p>
<p>$valid = array_diff_key($_POST, $exclude);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brandon Savage</title>
		<link>http://www.brandonsavage.net/searching-arrays-for-values/#comment-454</link>
		<dc:creator>Brandon Savage</dc:creator>
		<pubDate>Wed, 22 Apr 2009 17:43:10 +0000</pubDate>
		<guid isPermaLink="false">http://dev.brandonsavage.net/?p=105#comment-454</guid>
		<description>Jack, I have to disagree with your code sample. Simply doing if($array[$k]) will emit a notice if the array key does not exist. My code sample was designed to prevent this notice from being emitted. If you turn errors to E_ALL you&#039;ll see this notice, which I think we can both agree would slow down service of the site while the web server writes to the error logs.</description>
		<content:encoded><![CDATA[<p>Jack, I have to disagree with your code sample. Simply doing if($array[$k]) will emit a notice if the array key does not exist. My code sample was designed to prevent this notice from being emitted. If you turn errors to E_ALL you&#8217;ll see this notice, which I think we can both agree would slow down service of the site while the web server writes to the error logs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jack</title>
		<link>http://www.brandonsavage.net/searching-arrays-for-values/#comment-453</link>
		<dc:creator>jack</dc:creator>
		<pubDate>Wed, 22 Apr 2009 17:39:30 +0000</pubDate>
		<guid isPermaLink="false">http://dev.brandonsavage.net/?p=105#comment-453</guid>
		<description>Hi Brandon,

Just browsing around and came across your other post on superglobals in classes, then this one.

In the code above, the isset() call is redundant. Since you are setting the value to true, the following also works:

if ($array[$k])
    unset($_POST[$k]);

On large arrays, this is MUCH faster than the in_array() method and -- I&#039;d have to disagree with you -- more elegant, too.

For large arrays, you can always create the array normally and then use the array_flip() method to exchange the keys and values. You just have to be careful with the zero array element, but that&#039;s easy to get around by starting your array indexes at one:

$array = array(1 =&gt; &#039;somevalue&#039;, &#039;othervalue&#039;, &#039;newvalue&#039;...);

The indexes for othervalue, newvalue, etc... will now be 2, 3...  You can then use array_flip() to exchange the keys and values in the array. Since any number, other than zero, evaluates to true, the if statement above will still work.

--jack</description>
		<content:encoded><![CDATA[<p>Hi Brandon,</p>
<p>Just browsing around and came across your other post on superglobals in classes, then this one.</p>
<p>In the code above, the isset() call is redundant. Since you are setting the value to true, the following also works:</p>
<p>if ($array[$k])<br />
    unset($_POST[$k]);</p>
<p>On large arrays, this is MUCH faster than the in_array() method and &#8212; I&#8217;d have to disagree with you &#8212; more elegant, too.</p>
<p>For large arrays, you can always create the array normally and then use the array_flip() method to exchange the keys and values. You just have to be careful with the zero array element, but that&#8217;s easy to get around by starting your array indexes at one:</p>
<p>$array = array(1 =&gt; &#8216;somevalue&#8217;, &#8216;othervalue&#8217;, &#8216;newvalue&#8217;&#8230;);</p>
<p>The indexes for othervalue, newvalue, etc&#8230; will now be 2, 3&#8230;  You can then use array_flip() to exchange the keys and values in the array. Since any number, other than zero, evaluates to true, the if statement above will still work.</p>
<p>&#8211;jack</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk (feed is rejected)
Page Caching using apc (user agent is rejected)
Database Caching 44/51 queries in 0.040 seconds using disk
Content Delivery Network via Amazon Web Services: S3: files.brandonsavage.net.s3.amazonaws.com

Served from: www.brandonsavage.net @ 2010-07-31 11:14:29 -->