<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Associative array &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/associative-array/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>PHP: What is More Powerful Than list() &#8211; Perhaps extract()</title>
		<link>/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/</link>
		<comments>/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 15:49:35 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Associative array]]></category>
		<category><![CDATA[Comparison of programming languages]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Data structures]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[post]]></category>

		<guid isPermaLink="false">/?p=1942</guid>
		<description><![CDATA[list() in PHP Recently I wrote about list() in PHP which is indeed very powerful when assigning variable values from array elements. $a = array(10, array('here', 'are', 'some', 'tests')); list($count, $list) = $a; Actually my example in the post was not correct, because I wrote that you can pass an associative array, but the truth &#8230; <a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" class="more-link">Continue reading <span class="screen-reader-text">PHP: What is More Powerful Than list() &#8211; Perhaps extract()</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/27/php-what-is-more-powerful-than-list/" rel="bookmark" title="PHP: What is More Powerful Than list()">PHP: What is More Powerful Than list() </a></li>
<li><a href="/2011/10/19/thing-to-know-about-php-arrays/" rel="bookmark" title="Thing to Know About PHP Arrays">Thing to Know About PHP Arrays </a></li>
<li><a href="/2010/09/29/construct-a-sorted-php-linked-list/" rel="bookmark" title="Construct a Sorted PHP Linked List">Construct a Sorted PHP Linked List </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>list() in PHP</h2>
<p>Recently I wrote <a title="PHP: what is more powerful than list" href="/2010/08/27/php-what-is-more-powerful-than-list/" target="_blank">about list()</a> in PHP which is indeed very powerful when assigning variable values from array elements.</p>
<pre lang="php">
$a = array(10, array('here', 'are', 'some', 'tests'));
list($count, $list) = $a;
</pre>
<p>Actually my example in the post was not correct, because I wrote that you can pass an associative array, but the truth is that you cannot, and thus the array should be always with numeric keys. After noticing the comments of that post, and thanks to @Philip,  I searched a bit about how this problem can be overcome.</p>
<h2>There is a Solution</h2>
<p>As always PHP gives a perfect solution! You can see on the <a title="PHP: list - Manual" href="http://php.net/manual/en/function.list.php" target="_blank">list() doc page</a> that there is a function that may help you use an associative array.</p>
<h2>Extract</h2>
<p>extract() is perhaps less known than list(), but it does the right thing!</p>
<pre lang="php">
$a = array('count' => 10, 'list' => array('here', 'are', 'some', 'tests'));
extract($a);

echo $count;    // 10
print_r($list); // array('here'....
</pre>
<p>Note that now both $count and $list are defined.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/27/php-what-is-more-powerful-than-list/" rel="bookmark" title="PHP: What is More Powerful Than list()">PHP: What is More Powerful Than list() </a></li>
<li><a href="/2011/10/19/thing-to-know-about-php-arrays/" rel="bookmark" title="Thing to Know About PHP Arrays">Thing to Know About PHP Arrays </a></li>
<li><a href="/2010/09/29/construct-a-sorted-php-linked-list/" rel="bookmark" title="Construct a Sorted PHP Linked List">Construct a Sorted PHP Linked List </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: preg_match Give Names to the Matches</title>
		<link>/2010/07/03/php-preg_match-give-names-to-the-matches/</link>
		<comments>/2010/07/03/php-preg_match-give-names-to-the-matches/#respond</comments>
		<pubDate>Sat, 03 Jul 2010 17:57:28 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Associative array]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[maintainable code]]></category>
		<category><![CDATA[matches]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[preg_match]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">/?p=1725</guid>
		<description><![CDATA[So Called &#8211; Subpatterns In PHP 5.2.2+ you can name the sub patterns returned from preg_match with a specific syntax. Named subpatterns now accept the syntax (?&#60;name&#62;) and (?&#8217;name&#8217;) as well as (?P&#60;name&#62;). Previous versions accepted only (?P&#60;name&#62;) This is extremely helpful, when dealing with long patterns. As you may know you can simply use &#8230; <a href="/2010/07/03/php-preg_match-give-names-to-the-matches/" class="more-link">Continue reading <span class="screen-reader-text">PHP: preg_match Give Names to the Matches</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" rel="bookmark" title="PHP: What is More Powerful Than list() &#8211; Perhaps extract()">PHP: What is More Powerful Than list() &#8211; Perhaps extract() </a></li>
<li><a href="/2010/04/29/debugging-in-zend-framework/" rel="bookmark" title="Debugging in Zend Framework">Debugging in Zend Framework </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>So Called &#8211; Subpatterns</h2>
<p><a href="/wp-content/uploads/2010/07/patterns.jpeg"><img src="/wp-content/uploads/2010/07/patterns.jpeg" alt="Patterns - preg_match" title="patterns" width="430" height="89" class="aligncenter size-full wp-image-1767" srcset="/wp-content/uploads/2010/07/patterns.jpeg 430w, /wp-content/uploads/2010/07/patterns-300x62.jpg 300w" sizes="(max-width: 430px) 100vw, 430px" /></a></p>
<p>In PHP 5.2.2+ you can name the sub patterns returned from <a href="http://php.net/manual/en/function.preg-match.php" target="_blank">preg_match</a> with a specific syntax.</p>
<blockquote><p>Named subpatterns now accept the syntax (?&lt;name&gt;)  and (?&#8217;name&#8217;) as well as (?P&lt;name&gt;). Previous versions accepted only (?P&lt;name&gt;)</p></blockquote>
<p>This is extremely helpful, when dealing with long patterns. As you may know you can simply use the &#8220;old school&#8221; way and to call the matches by their number based index:</p>
<pre lang="php">
    $haystack = '01 Jan 1970';
    $pattern = '/(\d{1,2})\ (Jan|Feb)\ (19\d\d)/';

    preg_match($pattern, $haystack, $matches);

    print_r($matches);
</pre>
<p>Although it may look difficult to maintain, now you can simply name the sub patterns of preg_match and to call them with their associative array keys. This is more clear when writing code and it&#8217;s definitely more maintainable.</p>
<pre lang="php">
    $haystack = '01 Jan 1970';
    $pattern = '/(?<day>\d{1,2})\ (?<month>Jan|Feb)\ (?<year>19\d\d)/';

    preg_match($pattern, $haystack, $matches);

    print_r($matches);

    // now there's $matches['day'], $matches['month'] ...
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" rel="bookmark" title="PHP: What is More Powerful Than list() &#8211; Perhaps extract()">PHP: What is More Powerful Than list() &#8211; Perhaps extract() </a></li>
<li><a href="/2010/04/29/debugging-in-zend-framework/" rel="bookmark" title="Debugging in Zend Framework">Debugging in Zend Framework </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/07/03/php-preg_match-give-names-to-the-matches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Objects Coding Style</title>
		<link>/2010/05/24/javascript-objects-coding-style/</link>
		<comments>/2010/05/24/javascript-objects-coding-style/#comments</comments>
		<pubDate>Mon, 24 May 2010 07:48:50 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Associative array]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[Negation]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Scripting languages]]></category>

		<guid isPermaLink="false">/?p=1557</guid>
		<description><![CDATA[JavaScript vs. PHP Continuing from my post about PHP arrays coding style and following the comments of that post, I&#8217;d like to write a bit about JavaScript objects&#8217; coding style. You perhaps know that the term object is quite undefined or under estimated in the JavaScript world, but I&#8217;d speak about the key/value pairs in &#8230; <a href="/2010/05/24/javascript-objects-coding-style/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript Objects Coding Style</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/12/03/javascript-objects-coding-style-reviewed/" rel="bookmark" title="JavaScript Objects Coding Style Reviewed">JavaScript Objects Coding Style Reviewed </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/02/24/storing-javascript-objects-in-html5-localstorage/" rel="bookmark" title="Storing JavaScript objects in html5 localStorage">Storing JavaScript objects in html5 localStorage </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript vs. PHP</h2>
<p>Continuing from my <a title="PHP Arrays Coding Style" href="/2010/05/19/php-associative-arrays-coding-style/" target="_self">post</a> about PHP arrays coding style and following the comments of that post, I&#8217;d like to write a bit about JavaScript objects&#8217; coding style.</p>
<p>You perhaps know that the term object is quite undefined or under estimated in the JavaScript world, but I&#8217;d speak about the key/value pairs in JS commonly formatted like that:</p>
<pre lang="javascript">
var obj = { key : 'value' }
</pre>
<p>Here you can add more and more key/value pairs, but what&#8217;s different from the PHP associative arrays and what&#8217;s the same and should be cosidered.</p>
<h2>The Same as PHP?</h2>
<p>I wrote about the alignment in PHP and hashes. Than I showed how I align them:</p>
<pre lang="php">
$arr = array(
   'short'   => 'val',
   'longkey' => 'val'
);
</pre>
<p>In JavaScript you should use the same technique of alignment:</p>
<pre lang="php">
var obj = {
   'short'   : 'val',
   'longkey' : 'val'
};
</pre>
<h2>Some Differences</h2>
<p>Yes, there are more differences, which is normal. First of all you don&#8217;t have the =&gt; notation in JavaScript and a : is used. Second and most important you cannot add a trailing comma after the last key/value pair. Note that in PHP that&#8217;s fine!</p>
<pre lang="javascript">
// that will throw an error in MSIE
var obj = {
   'short'   : 'val',
   'longkey' : 'val',
};
</pre>
<p>while this is OK in PHP and it&#8217;s encouraged:</p>
<pre lang="php">
$arr = array(
   'short'   => 'val',
   'longkey' => 'val',
);
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/12/03/javascript-objects-coding-style-reviewed/" rel="bookmark" title="JavaScript Objects Coding Style Reviewed">JavaScript Objects Coding Style Reviewed </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/02/24/storing-javascript-objects-in-html5-localstorage/" rel="bookmark" title="Storing JavaScript objects in html5 localStorage">Storing JavaScript objects in html5 localStorage </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/05/24/javascript-objects-coding-style/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
