This is a javascript code that consists of hashmap array(keys:value).I created one function using map that returns values of entered keys.
var rule =
{
"c": "d",
"a": "o",
"t": "g",
"h": "a",
"e": "n",
"n": "t"
}
function convert(str) {
return [...str].map(d => rule[d]).join('')
}
console.log(convert("cat"))
//prints dog
Now I want to convert above javascript code in php so that i can run it under php server. I created same array in php as
$rule =
{
"c" => "d",
"a" => "o",
"t" => "g",
"h" => "a",
"e" => "n",
"n" => "t"
}
Using array_map,how to convert in php code in same way as done in javascript. Php syntax for array_map is
array_map(myfunction,array1,array2...)