News Feed
Jobs Feed
Sections




News Archive
feed this:

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

Chris Shiflett's Blog:
Sorting Multi-Dimensional Arrays in PHP
July 01, 2011 @ 09:48:26

In a sort of "remind himself later" kind of post, Chris Shiflett has shared a quick example of a common task PHP developers face sorting a multi-dimensional array.

Every time I need to sort a multi-dimensional array in PHP, I have to remind myself how to do it. It's not quite as quick and easy to look up as most things, so I'm going to blog a quick example. I've always felt like there must be a better way to do this, so please let me know if there is, and I'll update this post accordingly.

His method sorts a multi-dimensional array of user data using the array_multisort function together with a list of the usernames in each record. In the comments, people recommend using usort instead with a callback+closure combo that keeps things nice and clean.

0 comments voice your opinion now!
sort multidimensional array hint


Make Me Pulse Blog:
Tips RecursiveArrayIterator on mulitdimensional Array
February 11, 2008 @ 13:07:00

On the Make Me Pulse blog, Antoine Ughetto shares a method he came up with to recurse through an array using the SPL method - the RecursiveArrayIterator method.

When we have a multidimensional array we have to make some recursives function to parse it. A simple way to get the keys and the value of this type of array is to use the SPL library of PHP.

A code example is included, parsing through a recursive array to output each of the key/value pairs it contains (and using only about five or six lines of code to do it).

0 comments voice your opinion now!
spl library standard recursiveiteratoriterator multidimensional array


DevShed:
The Switch Statement and Arrays
January 07, 2008 @ 12:50:00

DevShed continues their series looking at some of the fundamentals of working with PHP in this new tutorial posted today. It looks at one of the flow control statements the language has to offer and a very useful data structure - the switch statement and arrays.

In our last exciting adventure (back in early November), we braved crocodiles, ravenous editors, most of the PHP statements, and beginning loops. In this edition we'll cover the final statement, the Switch, and discuss arrays. So sit back, order your R2D2 robot to bring you a cold, frosty Jolt Cola, and let's get cracking.

They start with a simple example of a switch statement (to echo out strings) and follow it with a detailed description of the different sorts of arrays - numeric indexed, associative and multidimensional versions.

1 comment voice your opinion now!
tutorial switch flow control array numeric associative multidimensional tutorial switch flow control array numeric associative multidimensional



Community Events











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


install package component facebook symfony2 framework series example hhvm security unittest composer code language opinion introduction release hack application podcast

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