<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Wed, 19 Jun 2013 07:35:42 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[PHPMaster.com: Using SPL Iterators, Part 2]]></title>
      <guid>http://www.phpdeveloper.org/news/17986</guid>
      <link>http://www.phpdeveloper.org/news/17986</link>
      <description><![CDATA[<p>
On PHPMaster.com today they've posted the <a href="http://phpmaster.com/using-spl-iterators-2/">second part of the series</a> covering the Iterators that come with PHP as a part of the <a href="http://php.net/spl">SPL</a>.
</p>
<blockquote>
In <a href="http://phpmaster.com/using-spl-iterators-1">part one</a> of this series I introduced you to some of the SPL Iterators and how to use them. There may be times however when the provided iterators are insufficient for your needs and you'll want to roll your own custom iterator. Luckily, SPL provides interfaces that will allow you to do just that. For an object to be traversable in a foreach loop, PHP requires that it be an instance of Traversable. You cannot however implement this interface directly (though you can use it in instaceof checks); instead you'll need to implement either SPL's Iterator or IteratorAggregate interfaces.
</blockquote>
<p>
He shows you how to implement these two interfaces in your own custom classes, looping through a set of books for the Iterator example and a "getIterator" method that creates an <a href="http://php.net/arrayiterator">ArrayIterator</a> when executed. The results of both are used in foreach loops showing how they can be used just like any other iteratable variables.
</p>]]></description>
      <pubDate>Tue, 22 May 2012 08:23:17 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Learning Loops]]></title>
      <guid>http://www.phpdeveloper.org/news/17264</guid>
      <link>http://www.phpdeveloper.org/news/17264</link>
      <description><![CDATA[<p>
PHPmaster.com has a new introductory tutorial for those just starting out with PHP (or with programming really) talking about <a href="http://phpmaster.com/loops/">using looping structures</a> for sets of data - for, while/do-while and foreach.
</p>
<blockquote>
A significant advantage of computers is that they can perform repetitive tasks easily and efficiently. Instead of writing repetitive code you can write a set of statements that processes some data and then have the computer execute them repeatedly by using a construct known as a loop. Loops come in several different flavors in PHP: for, while, do-while, and foreach. I'll introduce you to each of them and show you how they can making repetitive tasks straightforward and easy to maintain.
</blockquote>
<p>
The tutorial explains a use case for each of the loop types and includes a bit of sample code showing how to put it into practice. It also shares two special keywords that can be used to bypass or break out of your current loop - break and continue.
</p>]]></description>
      <pubDate>Thu, 15 Dec 2011 10:15:00 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Johannes Schluter's Blog: References and foreach]]></title>
      <guid>http://www.phpdeveloper.org/news/14999</guid>
      <link>http://www.phpdeveloper.org/news/14999</link>
      <description><![CDATA[<p>
To reinforce a point he's made before (references in PHP are bad) <i>Johannes Schluter</i> has <a href="http://schlueters.de/blog/archives/141-References-and-foreach.html">posted an example</a> to his blog of a specific instance that causes an (expected) issue with references and foreach loops.
</p>
<blockquote>
Now there is one use case which leads to an, at first, unexpected behavior which I didn't see as a real live issue when I stumbled over it at first, but then there were a few bug reports about it and recently a friend asked me about it ... so here it goes.
</blockquote>
<p>
He show a code snippet of looping over an array with two <a href="http://php.net/foreach">foreach</a>es and a <a href="http://php.net/print_r">print_r</a> that shows the bug - the array changed from the original for no clearly apparent reason. To understand why this happens, he goes into detail on how variables are handled - complete with graphs.
</p>]]></description>
      <pubDate>Fri, 20 Aug 2010 12:44:35 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Giorgio Sironi's Blog: Stop writing foreach() cycles]]></title>
      <guid>http://www.phpdeveloper.org/news/14050</guid>
      <link>http://www.phpdeveloper.org/news/14050</link>
      <description><![CDATA[<p>
<i>Giorgio Sironi</i> has a recommendation for developers out there - <a href="http://giorgiosironi.blogspot.com/2010/02/stop-writing-foreach-cycles.html">stop writing foreach loops</a>, there's something better in PHP 5.3+ - <a href="http://php.net/manual/en/functions.anonymous.php">closures</a>
</p>
<blockquote>
There are some array functions which have already been supported at least from Php 4, and that take as an argument a <a href="http://en.wikipedia.org/wiki/Callback_%28computer_science%29">callback</a> whose formal parameters have to be one or two elements of the array. [...] In Php 5.3, callbacks may also be specified as anonymous functions, defined in the middle of other code. These closures are first class citizens, and are treated as you would treat a variable, by passing it around as a method parameter.
</blockquote>
<p>
He includes some code examples to show you how closures used in callbacks can replace a lot of the other looping normally done by a separate bit of code. Most of the instances are in array functions that take in a callback and apply it to each element in the array (some recursively). The last example shows how to use it in a <a href="http://php.net/usort">usort</a> call to make the custom sorting of an array simpler.
</p>]]></description>
      <pubDate>Thu, 18 Feb 2010 10:58:28 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Leonid Mamchenkov's Blog: Perl vs. PHP : variable scoping]]></title>
      <guid>http://www.phpdeveloper.org/news/11559</guid>
      <link>http://www.phpdeveloper.org/news/11559</link>
      <description><![CDATA[<p>
<i>Leonid Mamchenkov</i> has compared Perl versus PHP in <a href="http://mamchenkov.net/wordpress/2008/12/12/perl-vs-php-variable-scoping/">this new blog post</a> - specifically how they handle variable scoping.
</p>
<blockquote>
I've mentioned quite a few times that I am a big fan of Perl programming language.  However, most of my programming time these days is spent in PHP.  The languages are often similar, with PHP having its roots in Perl, and Perl being such a influence in the world of programming languages.  This similarity is often very helpful.  However there are a few difference, some of which are obvious and others are not.
</blockquote>
<p>
His example compares looping (a foreach in both) and how, after the Perl loop the $value variable is no longer accessible. In PHP, however, it's passed back out into the current scope and can be read just like any other variable. While this can be useful, it can also cause headaches when trying to track down elusive bugs.
</p>]]></description>
      <pubDate>Fri, 12 Dec 2008 08:49:14 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Felix Geisendorfer's Blog: Sorting Challenge]]></title>
      <guid>http://www.phpdeveloper.org/news/8911</guid>
      <link>http://www.phpdeveloper.org/news/8911</link>
      <description><![CDATA[<p>
<i>Felix Geisendorfer</i> has a <a href="http://www.thinkingphp.org/2007/10/25/sorting-challenge/">quick little sorting example</a> posted today showing on way to sort a multi-dimensional array.
</p>
<blockquote>
Quick challenge, lets say you have an array and you want to iterate through your products by [the key of each subarray in $products] Product.ordering ASC. Whats the fastest way to do this? 
</blockquote>
<p>
<a href="http://www.thinkingphp.org/2007/10/25/sorting-challenge/">His solution</a> involves using an array_flip call on the extracted information (using Set::extract), ordering it with ksort and pushing the values back into the $product array in the right order.
</p>
<p>
Check out <a href="http://www.thinkingphp.org/2007/10/25/sorting-challenge/">the comments</a> for more examples including ones that make use of array_multisort.
</p>]]></description>
      <pubDate>Fri, 26 Oct 2007 08:42:00 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[HowToForge.com: Loops In PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/7190</guid>
      <link>http://www.phpdeveloper.org/news/7190</link>
      <description><![CDATA[<p>
On the HowToForge website, there's <a href="http://www.howtoforge.com/loops_in_php">a new tutorial</a> that teaches one of the fundamentals of working with PHP (or any language for that matter) - looping.
</p>
<blockquote>
Let's move towards our today's lecture which is about Loops. There are certain conditions in which you need to execute the same block of code again and again. For example if you want to print ten consecutive equal signs in three lines to make a separator then you could do it with different methods. 
</blockquote>
<p>
<a href="http://www.howtoforge.com/loops_in_php">The tutorial</a> covers:
<ul>
<li>Basic Concept Of Loops
<li>Types Of Loops (for, while, do/while, and foreach)
<li>Assignment
<li>some Related Articles
</ul>
Code examples are given for all, and a good overview of working with the loops is given.
</p>]]></description>
      <pubDate>Tue, 30 Jan 2007 12:26:00 -0600</pubDate>
    </item>
  </channel>
</rss>
