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
Jul 01, 2011 @ 14: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.

tagged: sort multidimensional array hint

Link:

Make Me Pulse Blog:
Tips : RecursiveArrayIterator on mulitdimensional Array
Feb 11, 2008 @ 19: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).

tagged: spl library standard recursiveiteratoriterator multidimensional array

Link:

DevShed:
The Switch Statement and Arrays
Jan 07, 2008 @ 18: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.

tagged: tutorial switch flow control array numeric associative multidimensional tutorial switch flow control array numeric associative multidimensional

Link:

DevShed:
The Switch Statement and Arrays
Jan 07, 2008 @ 18: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.

tagged: tutorial switch flow control array numeric associative multidimensional tutorial switch flow control array numeric associative multidimensional

Link:


Trending Topics: