Flexihash\Hasher\Md5Hasher::hash PHP Method

hash() public method

8 hexits = 32bit, which also allows us to forego having to check whether it's over PHP_INT_MAX. The substring is converted to an int since hex strings sometimes get treated as ints if all digits are ints and this results in unexpected sorting order.
Author: Dom Morgan ([email protected])
public hash ( string $string ) : integer
$string string
return integer
    public function hash($string)
    {
        return hexdec(substr(md5($string), 0, 8));
    }

Usage Example

Example #1
0
 public function testMd5Hash()
 {
     $hasher = new Md5Hasher();
     $result1 = $hasher->hash('test');
     $result2 = $hasher->hash('test');
     $result3 = $hasher->hash('different');
     $this->assertEquals($result1, $result2);
     $this->assertNotEquals($result1, $result3);
     // fragile but worthwhile
 }
All Usage Examples Of Flexihash\Hasher\Md5Hasher::hash
Md5Hasher