News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Edd Mann:
Tuples in PHP
April 18, 2014 @ 09:48:38

Edd Mann has a new post today sharing some of his exploration into implementing tuples in PHP. A tuple is a common data structure in other languages consisting of an immutable, ordered list of items.

Since exploring languages such as Scala and Python which provide the tuple data-structure, I have been keen to experiment with how to clearly map it into a PHP solution. Tuples are simply a finite, ordered sequence of elements - usually with good language support to both pack (construction) and unpack (deconstruction) of the values. I have found that many use-cases of the common place array structure in PHP could be better suited to n-tuple's. [...] I discussed briefly that what makes tuples so powerful in the highlighted languages is their good support for handling their contents, for example unpacking a user tuple into separate id and name variables. PHP supports this form of unpacking in regard to arrays using the 'list' function, which I frequently use to return multiple values from a function/method invocation.

He shares the code for his basic implementation, extended from the SplFixedArray, and shows an example of it in use. He also includes samples showing how to make typed tuples via a "type" method call.

0 comments voice your opinion now!
tuple data structure splfixedarray example tutorial

Link: http://eddmann.com/posts/tuples-in-php/

blog comments powered by Disqus

Similar Posts

NETTUTS.com: Quick Tip: Loop Through Folders with PHP’s Glob()

IBM developerWorks: Integrate Google Book Search into a PHP application

PHPMaster.com: Functional Programming and PHP

Lorna Mitchell's Blog: Retrieving Data from Google Analytics API using PHP

PHPMaster.com: Using Facebook’s Realtime Updates and Subscription API


Community Events





Don't see your event here?
Let us know!


opinion framework install update api release package library interview podcast series symfony tips introduction zendserver language deployment list laravel community

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework