<?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: PHP: Get First Index in Associative Array</title>
	<atom:link href="http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/</link>
	<description>yes i love technology</description>
	<lastBuildDate>Thu, 19 Aug 2010 08:26:20 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Tom</title>
		<link>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/comment-page-1/#comment-85240</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Thu, 03 Dec 2009 20:38:43 +0000</pubDate>
		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/#comment-85240</guid>
		<description>reset is much better, please update your (dirty) post ;-)

But you could make a more usefull function:

		public static function getItemAt($collection,$index)
		{			
			if ($index &gt;= 0 &amp;&amp; $index &lt; count($collection))
			{
				$i = 0;
				
				foreach ($collection AS $item)
				{
					if ($i++ == $index)
					{
						return $item;
					}
				}
			}
			
			return null;
		}</description>
		<content:encoded><![CDATA[<p>reset is much better, please update your (dirty) post <img src='http://tech.petegraham.co.uk/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>But you could make a more usefull function:</p>
<p>		public static function getItemAt($collection,$index)<br />
		{<br />
			if ($index &gt;= 0 &amp;&amp; $index &lt; count($collection))<br />
			{<br />
				$i = 0;</p>
<p>				foreach ($collection AS $item)<br />
				{<br />
					if ($i++ == $index)<br />
					{<br />
						return $item;<br />
					}<br />
				}<br />
			}</p>
<p>			return null;<br />
		}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: benjy77</title>
		<link>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/comment-page-1/#comment-73972</link>
		<dc:creator>benjy77</dc:creator>
		<pubDate>Fri, 05 Jun 2009 14:05:04 +0000</pubDate>
		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/#comment-73972</guid>
		<description>reset() returns first value

reset() followed by each() or key() should give you the first key/value

drawback: internal pointer gets lost using reset()</description>
		<content:encoded><![CDATA[<p>reset() returns first value</p>
<p>reset() followed by each() or key() should give you the first key/value</p>
<p>drawback: internal pointer gets lost using reset()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/comment-page-1/#comment-56684</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Mon, 26 Jan 2009 15:08:21 +0000</pubDate>
		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/#comment-56684</guid>
		<description>You can use the key() function for an associative array.

This will return the first key name, eg $keyname = key($array);

You can then use next() and prev() to get keys that follow.

So if i quickly wanted the 3rd key id do this:

next($array);
next($array);
next($array);
$keyname = key($array);


 

The current() function is best used on</description>
		<content:encoded><![CDATA[<p>You can use the key() function for an associative array.</p>
<p>This will return the first key name, eg $keyname = key($array);</p>
<p>You can then use next() and prev() to get keys that follow.</p>
<p>So if i quickly wanted the 3rd key id do this:</p>
<p>next($array);<br />
next($array);<br />
next($array);<br />
$keyname = key($array);</p>
<p>The current() function is best used on</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Goodman</title>
		<link>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/comment-page-1/#comment-14846</link>
		<dc:creator>Peter Goodman</dc:creator>
		<pubDate>Thu, 24 Apr 2008 00:14:36 +0000</pubDate>
		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/#comment-14846</guid>
		<description>Why not simply use current($array); ?</description>
		<content:encoded><![CDATA[<p>Why not simply use current($array); ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ian</title>
		<link>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/comment-page-1/#comment-10902</link>
		<dc:creator>ian</dc:creator>
		<pubDate>Mon, 17 Dec 2007 11:10:22 +0000</pubDate>
		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/#comment-10902</guid>
		<description>Yes i think just using array_keys() to get all the indexes, which then means you have an array like [0] =&gt; array_key1, [1] =&gt; array_key2 etc. You can then use the index to get the key you are interested in.</description>
		<content:encoded><![CDATA[<p>Yes i think just using array_keys() to get all the indexes, which then means you have an array like [0] =&gt; array_key1, [1] =&gt; array_key2 etc. You can then use the index to get the key you are interested in.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Charles Rowe</title>
		<link>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/comment-page-1/#comment-3854</link>
		<dc:creator>Charles Rowe</dc:creator>
		<pubDate>Tue, 12 Jun 2007 19:19:08 +0000</pubDate>
		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/#comment-3854</guid>
		<description>just use key() before you start traversing the array. Am I missing something about the problem?</description>
		<content:encoded><![CDATA[<p>just use key() before you start traversing the array. Am I missing something about the problem?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: &#187; Obtener el primer valor de una matriz asociativa en PHP &#187; Pensando! &#187; Archivo del Blog</title>
		<link>http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/comment-page-1/#comment-3731</link>
		<dc:creator>&#187; Obtener el primer valor de una matriz asociativa en PHP &#187; Pensando! &#187; Archivo del Blog</dc:creator>
		<pubDate>Sat, 09 Jun 2007 01:25:28 +0000</pubDate>
		<guid isPermaLink="false">http://tech.petegraham.co.uk/2007/05/15/php-get-first-index-in-associative-array/#comment-3731</guid>
		<description>[...] Despues de pasarme un rato googleando me topo de que php no trae una funcion para acceder al primer elemento de una matriz asociativa, Algo extrano de que php no tenga una funcion implicita para realizar esto, al final (como me lo imaginaba, pero no queria aceptar que no existira tal función  )) recurri al amigo foreach como nos cuenta tech.petegraham.co.uk [...]</description>
		<content:encoded><![CDATA[<p>[...] Despues de pasarme un rato googleando me topo de que php no trae una funcion para acceder al primer elemento de una matriz asociativa, Algo extrano de que php no tenga una funcion implicita para realizar esto, al final (como me lo imaginaba, pero no queria aceptar que no existira tal función  )) recurri al amigo foreach como nos cuenta tech.petegraham.co.uk [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

