Login   Register  
PHP Classes
elePHPant
Icontem

Walker: Convert an array into hierarchic data

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2010-12-03 (3 years ago) RSS 2.0 feedNot enough user ratingsTotal: 485 All time: 5,354 This week: 1,500Up
Version License PHP version Categories  
walker 1.1MIT/X Consortium License5Algorithms, Data types
Description Author  

This class can be used to convert an array into hierarchic data.

It can traverse an array of elements which may be objects or arrays that have entries that define an identifier of the entry and the identifier of the parent entry.

The class calls a certain class function to process entries grouped by parent entry identifier.

That function returns a string that is concatenated to form the whole hierarchy string representation.

Sub-classes my redefine the entry processing function to generate a string in a hierarchic format.

Innovation Award  
PHP Programming Innovation award nominee
November 2010
Number 6


Prize: One year subscription to the PDF edition of the JSMag magazine
Databases are often used to store records of data that form hierarchic trees. Usually there is one field that represents the record identifier and another that represents the identifier of the parent record.

If you want to output those data records in an hierarchic format such as XML or JSON, you need to properly traverse the retrieved data records and group them appropriately according to the parent of each record.

This class can be used to do exactly data. It takes an array of hierarchic data records eventually retrieved from database and generates the respective serialized representation in XML or JSON format.

Manuel Lemos
Picture of Arthur Borisow
Name: Arthur Borisow <contact>
Classes: 3 packages by
Country: Ukraine Ukraine
Age: ???
All time rank: 154727 in Ukraine Ukraine
Week rank: 774 Up17 in Ukraine Ukraine Up
Innovation award
Innovation award
Nominee: 1x

  Files folder image Files  
File Role Description
Accessible without login Plain text file test.php Example Shows how to use the Walker class
Plain text file walker.class.php Class The class to generate hierarchy from arrays

 Version Control Unique User Downloads Download Rankings  
 0%Total:485All time:5,354
 This week:0This week:1,500Up
 User Comments (1)  
 
I like it!
3 years ago (Alex)
70%StarStarStarStar