This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function stringSimilarity( $a) { | |
| $a = trim($a); | |
| $cutPrefix = $sum = 0; | |
| $length = strlen($a); | |
| do{ | |
| $count = 0; | |
| while($a[$count] === substr($a,$cutPrefix+($count++), 1)){} | |
| $sum += $count -1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function salesForceIdChecksum($id) | |
| { | |
| $map = implode('',array_merge(range('A', 'Z'), range(0, 9))); | |
| $checksum = ''; | |
| foreach (str_split($id, 5) as $chunk) { | |
| $checksum .= substr($map, bindec( strrev(array_reduce(str_split($chunk, 1),function($carry, $item){ | |
| $carry .= (!is_numeric($item) && $item == strtoupper($item)) ? '1' : '0'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Recursive builder pattern | |
| * | |
| * Usage: | |
| * $tree = \Tree\Builder::init() | |
| * ->setName('parent') | |
| * ->addChild() |
NewerOlder