PHP Classes

Walker: Convert an array into hierarchic data

Recommend this page to a friend!
  Info   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 56%Total: 501 This week: 1All time: 5,806 This week: 560Up
Version License PHP version Categories
walker 1.1MIT/X Consortium ...5Algorithms, 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: 162828 in Ukraine Ukraine
Week rank: 416 Up8 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:501
This week:1
All time:5,806
This week:560Up
User Ratings User Comments (1)
 All time
Utility:83%StarStarStarStarStar
Consistency:75%StarStarStarStar
Documentation:-
Examples:75%StarStarStarStar
Tests:-
Videos:-
Overall:56%StarStarStar
Rank:1747
 
I like it!
13 years ago (Alex)
70%StarStarStarStar