 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Joshua Thijssen's Blog: SPL Using the iteratorAggregate interface
by Chris Cornutt December 06, 2011 @ 08:28:45
Joshua Thijssen has a recent post spotlighting a part of the Standard PHP Library (SPL) that implements that Traversable interface, the IteratorAggregate interface.
Together with its more famous brother "Iterator", they are currently the two only implementations of the "Traversable" interface, which is needed for objects so they can be used within a standard foreach() loop. But why and when should we use the iteratorAggregate?
He answers his question with an example - a book that contains chapters. With a normal iterator you'd have to define standard functions (like valid, rewind or key). Using the IteratorAggregate you can push items into an internal array (like chapters in a book) and call a "getIterator" method to get this set. He also takes it one step further and shows implementing the "Count" interface to make it easier to get a total count of the items in the iterator. Sample code is included to help clarify.
voice your opinion now!
spl iteratoraggregate interface traversable count
Havard Eide's Blog: Countable
by Chris Cornutt August 01, 2008 @ 10:23:28
In a new post Havard Eide looks at the creation of a Countable interface that can be used in any application:
Today I will look at the Countable interface, it has a single function that needs to be implemented: count(), by implementing this you can ensure that there is a count() function ready to use on any given class that implements it. The Countable interface is used in other places in the SPL as well: the ArrayIterator and ArrayObject classes implements this interface ( and SqliteResult if present ).
In his code examples he shows simple methods for returning the count() of a property, but notes that the real power of it comes in the ability to manipulate the number returned from the call based on other parameters (or filtering).
voice your opinion now!
countable interface count spl arrayiterator arrayobject
Developer Tutorials Blog: Building Web 2.0 Tag Clouds in PHP
by Chris Cornutt May 02, 2008 @ 13:15:27
The Developer Tutorials blog has posted a tutorial showing you how to set up a tag cloud for your site:
Every major website seems to have a tag cloud. Users love tag clouds; they help navigate masses of content quickly and easily. [...] How do we actually build a tag cloud at application level? In this tutorial, I'll take you through putting together a full-blown, calculated web 2.0 tag cloud in PHP.
They start at the end, with an example cloud with some sample tags ("php" being the largest, of course). The code for it is pretty simple - it looks at an array of counts, the number of times the tag is used, and builds the links with the correct font size automatically.
voice your opinion now!
tag cloud tutorial automatic count
Ryan Malesevich's Blog: iTunes Stats for Macintosh with PHP & MySQL Part 2
by Chris Cornutt August 14, 2006 @ 10:55:41
Ryan Malesevich is back today with part two of his "iTunes Stats for Macintosh with PHP and MySQL" series, building on the groundwork laid in part one.
As promised I'm back again the second and should be the last part for the iTunes stats with PHP & MySQL. In the previous section I covered how to get your iTunes information from iTunes into a MySQL database. Since I didn't get any questions about it I can either assume that no one cares or no one had any troubles.
This part is not exclusive to a Mac, you can write your PHP scripts with any operating system that you want. So if you're not on a Mac but has a friend who does then you can send your friend your iTunes XML file and your friend can export the data for you. Let's get stated shall we.
Since in the first part of the series, he showed how to put information into the database, he shows in this second part how to get things back out. There's code samples for connecting to the database, the SQL to grab all of the data out from the table and echo out the information inside. He also links to his stats as an example.
voice your opinion now!
itunes stats part2 macintosh display database play count itunes stats part2 macintosh display database play count
Limitless Studios: Determine Number Of Online Users Without A Database
by Chris Cornutt June 22, 2006 @ 14:49:39
From the Limitless Studios website, there's a new tutorial for those frustrated by the other "who's online" tutorials that require a database. Their example doesn't, opting instead to handle the process with PHP's sessions.
Most web developers will usually like to determine the number of online users currently browsing their web site. Most tutorials will teach you how to do just that using a database of some sort because it is easy to implant. Using a database though can be a bit slow at times, especially if your web site gets a lot of hits. In this tutorial, we will teach you an alternative and effective way to determine the number of online users WITHOUT using a database.
They note the overhead that using a database can cause, and look instead to something PHP works with natively - sessions. Their code is contained inside of a function, checking the session path PHP uses for session files that haven't expired yet.
voice your opinion now!
tutorial users online function session path count tutorial users online function session path count
|
Community Events
Don't see your event here? Let us know!
|