how to know function value? and hash them

i want ask how to hash value from my function (sorry about my bad word i just know a little bit). example:

function test($key){
    $r = 0;
    while($r < strlen($key)){
        $word = substr($key, $r, 1);
        $result = '';
        if($word == 'a' || $word == 'k' || $word == 'u'){$result = '0';}else{
        if($word == 'b' || $word == 'l' || $word == 'v'){$result = '1';}else{
        if($word == 'c' || $word == 'm' || $word == 'w'){$result = '2';}else{
        if($word == 'd' || $word == 'n' || $word == 'x'){$result = '3';}else{
        if($word == 'e' || $word == 'o' || $word == 'y'){$result = '4';}else{
        if($word == 'f' || $word == 'p' || $word == 'z'){$result = '5';}else{
        if($word == 'g' || $word == 'q'){$result = '6';}else{
        if($word == 'h' || $word == 'r'){$result = '7';}else{
        if($word == 'i' || $word == 's'){$result = '8';}else{
        if($word == 'j' || $word == 't'){$result = '9';}
        }}}}}}}}};
        $r++;
        $result;
    }

}
hash('sha256', test("keyvalue"));

when i want to echo the function doesn't display anything

1 answer

  • answered 2020-01-14 01:59 Seth B

    Simply add return $result; after your while statement ends