PHP Classes

File: examples/basic_strings.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of Thomas Björk  >  TTreeList  >  examples/basic_strings.php  >  Download  
File: examples/basic_strings.php
Role: Example script
Content type: text/plain
Description: Basic example using associated array
Class: TTreeList
Create a binary tree from array or database result
Author: By
Last change:
Date: 9 months ago
Size: 1,261 bytes


Class file image Download
include '../treelist.php';

// Create a TreeList
$tree = new TTreeList();

// Add some sample data to the tree

// Check how many records we have
echo "The treelist has ".count($tree)." nodes".PHP_EOL;
// Loop the tree as an array
foreach($tree as $node) {
' '.$node[0].' - '.$node[1];

// Build the tree and index it on the second index
echo "Building tree".PHP_EOL;

// Display the amount of nodes in the tree (returns 10 since we have two
// duplicates)
echo "There is ".$tree->treeCount." nodes in the tree".PHP_EOL;

// Locate a node in the tree
$node = $tree->Seek("delta");
// If we found a match then display it
if($node !== null) {
"Found match".PHP_EOL;
// Display the number of nodes that matches the search
echo "The match has ".$node->PayloadCount()." data nodes".PHP_EOL;