<?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>Notation &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/notation/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>Using PHP&#8217;s array_diff in Algorithm Development</title>
		<link>/2010/10/03/using-php-array_diff-in-algorithm-development/</link>
		<comments>/2010/10/03/using-php-array_diff-in-algorithm-development/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 10:51:54 +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[Computing]]></category>
		<category><![CDATA[Control flow]]></category>
		<category><![CDATA[Data structures]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Foreach]]></category>
		<category><![CDATA[Notation]]></category>

		<guid isPermaLink="false">/?p=2010</guid>
		<description><![CDATA[array_diff can be really powerful. Once you&#8217;ve to find the different elements between two arrays you&#8217;ve to use array_diff. Here&#8217;s a case when you can use it while coding a simple algorithm. The Task You&#8217;ve one array with tickets of linked destinations &#8211; so you start from one city to another, than next and so &#8230; <a href="/2010/10/03/using-php-array_diff-in-algorithm-development/" class="more-link">Continue reading <span class="screen-reader-text">Using PHP&#8217;s array_diff in Algorithm Development</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="/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="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
<li><a href="/2010/08/29/beginning-algorithm-complexity-and-estimation/" rel="bookmark" title="Beginning Algorithm Complexity and Estimation">Beginning Algorithm Complexity and Estimation </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><a title="PHP: array_diff" href="http://php.net/manual/en/function.array-diff.php" target="_blank">array_diff</a> can be really powerful. Once you&#8217;ve to find the different elements between two arrays you&#8217;ve to use array_diff. Here&#8217;s a case when you can use it while coding a simple algorithm.</p>
<h2>The Task</h2>
<p>You&#8217;ve one array with tickets of linked destinations &#8211; so you start from one city to another, than next and so on. Each element is an array with &#8220;from&#8221; and &#8220;to&#8221; destinations:</p>
<pre lang="php">
$inputTickets = array(
    0 => array('from' => 'barcelona', 'to' => 'madrid'),
    1 => array('from' => 'sofia', 'to' => 'paris'),
    2 => array('from' => 'madrid', 'to' => 'milano'),
    3 => array('from' => 'paris', 'to' => 'barcelona'),
    4 => array('from' => 'cupertino', 'to' => 'sofia'),
    5 => array('from' => 'milano', 'to' => 'valencia'),
    6 => array('from' => 'valencia', 'to' => 'nice'),
    7 => array('from' => 'mountain view', 'to' => 'cupertino'),
);
</pre>
<p>It&#8217;s easy to construct two arrays &#8211; the &#8220;from&#8221; destinations array and the &#8220;to&#8221; destinations array, and here the easiest way to get the starting point of the whole trip, because of the fact that these are linked tickets.</p>
<pre lang="php">
$fromDestinations = $toDestinations = array();

foreach ($inputTickets as $k => $v) {
    $fromDestinations[] = $v['from'];
    $toDestinations[]   = $v['to'];
}

// and finally get the starting point
$startPoint = array_diff($fromDestinations, $toDestinations);
</pre>
<h2>Conclusion</h2>
<p>Beside of knowing several algorithm techniques, there&#8217;s also need of knowing the language syntax and possibilities &#8211; in that case PHP&#8217;s</p>
<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="/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="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
<li><a href="/2010/08/29/beginning-algorithm-complexity-and-estimation/" rel="bookmark" title="Beginning Algorithm Complexity and Estimation">Beginning Algorithm Complexity and Estimation </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/10/03/using-php-array_diff-in-algorithm-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
