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

Pieter's Blog: Zend_Form with XML Tutorial

IBM developerWorks: Squash bugs in PHP applications with Zend Debugger

Knp Labs: Deploy Your Symfony Application Painlessly with Capifony

Dzone.com: A Free Amazon EC2 Cloud Server Based LAMP

Sameer Borate's Blog: Building a Graph data structure in PHP


Community Events

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


php7 conference extension version introduction framework symfony2 voicesoftheelephpant api series example podcast laravel performance release install library interview opinion community

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