PHP Classes

PHP Hashtable Array: Store key-value pairs in hashed arrays

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 8 All time: 11,514 This week: 560Up
Version License PHP version Categories
hashtable 1.0Free For Educatio...5PHP 5, Data types
Description 

Author

This class can store key-value pairs in hashed arrays.

It can compute an integer for the index of a hash table entry based on the key string.

The class uses the computed hash index to find the internal array position to find, insert, delete or update the value of the key, as well clear the whole hash table, check if an entry with a key exists, check if the list is empty or get the size of the list.

Picture of Dev Sharma
  Performance   Level  
Innovation award
Innovation award
Nominee: 2x

 

Example

<?php
require_once 'hash.class.php';

//example 1
$init = new hashtable;
$init->set('test', 'data');

$result = $init->get('test'); //returns data as your value
//

//example 2
$init = new hashtable;
$init->set('test', 'data');
$init->set('test2', 55);
$init->deleteit('test');

$result = $init->get('test'); //the value does not exist
//

//example 3
$init = new hashtable;
$result = $init->isempty(); //true
$init->set('getme', 'apple');
$result1 = $init->isempty(); //false
//

//example 4
$init = new hashtable;
$init->set('getme', 'apple');
$init->set('getme2', 'apple2');
$init->set('getme3', 'apple3');

$result = $init->isempty();
if(!
$result) $init->clear();

$result = $init->get('getme'); //the value does not exist
//

//example 5
$init = new hashtable;
$init->set('getme', 'apple');
$init->set('getme2', 'apple2');
$init->set('getme3', 'apple3');

$result = $init->getsize();

if(
$result >= 3) //code
//

//example 6
$init = new hashtable;
$init->set('getme', 'apple');
$init->set('getme2', 'apple2');
$init->set('getme3', 'apple3');

$result = $init->has('getme'); //true
//
?>


  Files folder image Files (2)  
File Role Description
Accessible without login Plain text file example.php Example An example
Plain text file hash.class.php Class main class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:8
This week:0
All time:11,514
This week:560Up