<?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: Checking for the presence of the arrays in&#160;PHP</title>
	<atom:link href="http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235/feed" rel="self" type="application/rss+xml" />
	<link>http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235</link>
	<description></description>
	<lastBuildDate>Wed, 15 Sep 2010 22:35:31 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Sid</title>
		<link>http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235/comment-page-1#comment-174943</link>
		<dc:creator>Sid</dc:creator>
		<pubDate>Fri, 23 Mar 2007 15:15:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235#comment-174943</guid>
		<description>I hate to burst your bubble but is_array is faster. Looking at your code you could have used microtime (with the parameter set to true), better yet you should have used PEAR&#039;s Benchmark. I did and comparing isset($array[0]) to is_array came up with:

Below results where when the function were checking the integer 123.
Mean execution time for is_array: 0.000121051421165
Mean execution time for isset: 0.000126702299118 
Below results where when the function were checking the array (1,2,3)
Mean execution time for is_array: 0.000145638279915
Mean execution time for isset: 0.000153319172859 

Also note that the count() function does &lt;strong&gt;not actually count the number of elements. If you look at the struct for a PHP variable (the same for all data types) it&#039;s simple an attribute that count reads which gets changed whenever the arrays length ever changes.

Considering is_array is easier to read, catches more &quot;edge&quot; cases (if they can be called that) and it slightly quick I&#039;d say that&#039;s what should be used.

Dixon: empty could simply return the wrong information and it&#039;s actually the same speed as is_array anyway,&lt;/strong&gt;</description>
		<content:encoded><![CDATA[<p>I hate to burst your bubble but is_array is faster. Looking at your code you could have used microtime (with the parameter set to true), better yet you should have used PEAR&#8217;s Benchmark. I did and comparing isset($array[0]) to is_array came up with:</p>
<p>Below results where when the function were checking the integer 123.<br />
Mean execution time for is_array: 0.000121051421165<br />
Mean execution time for isset: 0.000126702299118<br />
Below results where when the function were checking the array (1,2,3)<br />
Mean execution time for is_array: 0.000145638279915<br />
Mean execution time for isset: 0.000153319172859 </p>
<p>Also note that the count() function does <strong>not actually count the number of elements. If you look at the struct for a PHP variable (the same for all data types) it&#8217;s simple an attribute that count reads which gets changed whenever the arrays length ever changes.</p>
<p>Considering is_array is easier to read, catches more &#8220;edge&#8221; cases (if they can be called that) and it slightly quick I&#8217;d say that&#8217;s what should be used.</p>
<p>Dixon: empty could simply return the wrong information and it&#8217;s actually the same speed as is_array anyway,</strong></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dixon</title>
		<link>http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235/comment-page-1#comment-161770</link>
		<dc:creator>Dixon</dc:creator>
		<pubDate>Wed, 07 Mar 2007 22:52:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235#comment-161770</guid>
		<description>Sorry for lifting this post up... But how abaout empty() ???</description>
		<content:encoded><![CDATA[<p>Sorry for lifting this post up&#8230; But how abaout empty() ???</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Trachtenberg</title>
		<link>http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235/comment-page-1#comment-110411</link>
		<dc:creator>Adam Trachtenberg</dc:creator>
		<pubDate>Mon, 25 Sep 2006 21:19:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235#comment-110411</guid>
		<description>You should be careful with this syntax, as this will cause problems when $array is a string because $a[0] will be set to the first character of the string.

Personally, I find is_array() to be far and away the most clearly named of all the PHP functions you can use to test is a variable is an array, so I always use that regardless of any minimal speed benefit another function may have.</description>
		<content:encoded><![CDATA[<p>You should be careful with this syntax, as this will cause problems when $array is a string because $a[0] will be set to the first character of the string.</p>
<p>Personally, I find is_array() to be far and away the most clearly named of all the PHP functions you can use to test is a variable is an array, so I always use that regardless of any minimal speed benefit another function may have.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235/comment-page-1#comment-109710</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 23 Sep 2006 00:17:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235#comment-109710</guid>
		<description>Ok, I stand corrected, if (isset($array[0])) is the fastest option and it accounts for $array[0] being equal to zero.</description>
		<content:encoded><![CDATA[<p>Ok, I stand corrected, if (isset($array[0])) is the fastest option and it accounts for $array[0] being equal to zero.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergey Chernyshev</title>
		<link>http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235/comment-page-1#comment-109640</link>
		<dc:creator>Sergey Chernyshev</dc:creator>
		<pubDate>Fri, 22 Sep 2006 20:26:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.moskalyuk.com/blog/checking-for-the-presence-of-the-arrays-in-php/1235#comment-109640</guid>
		<description>You assume that if there is no 0th element then array is empty. Is it correct assumption?

I thought that PHP&#039;s arrays are associative arrays and there can be $array[&#039;abc&#039;] but not $array[0].

In any case, your solution might be much better if you know that array is not associative.

Also, what will happen in your code if $array1[0] equals 0 - will it return true or false?</description>
		<content:encoded><![CDATA[<p>You assume that if there is no 0th element then array is empty. Is it correct assumption?</p>
<p>I thought that PHP&#8217;s arrays are associative arrays and there can be $array['abc'] but not $array[0].</p>
<p>In any case, your solution might be much better if you know that array is not associative.</p>
<p>Also, what will happen in your code if $array1[0] equals 0 &#8211; will it return true or false?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

