I have some JS code which I want to convert to PHP code. I changed all the things that I know should, but it doesn't give the same result.
The PHP code I created from the JS code:
<?php
function hashCode($str){
$hash = 0;
if (strlen($str) == 0) return $hash;
for ($i = 0; $i < strlen($str); $i++) {
$char = $str[$i];
$hash = (($hash<<5) - $hash) + $char;
$hash = $hash & $hash;
}
return $hash;
}
?>
When entering a string
it returns 0 and that is not because of the if function.
Original code:
hashCode = function(str){
var hash = 0;
if (str.length == 0) return hash;
for (i = 0; i < str.length; i++) {
char = str.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
Can someone please help me?
Arend-Jan