I have an function that checks if string( parameter) matches values in an array and returns an array of possibilities key
function find_possible_match( $criteria ) {
$possible_match = array();
$possibilities = array(
"a"=>".-",
"b"=>"-...",
"c"=>"-.-.",
"d"=>"-..",
"e"=>".",
"f"=>"..-.",
"g"=>"--.",
"h"=>"....",
"i"=>"..",
"j"=>".---",
"k"=>"-.-",
"l"=>".-..",
"m"=>"--",
"n"=>"-.",
"o"=>"---",
"p"=>".--.",
"q"=>"--.-",
"r"=>".-.",
"s"=>"...",
"t"=>"-",
"u"=>"..-",
"v"=>"...-",
"w"=>".--",
"x"=>"-..-",
"y"=>"-.--",
"z"=>"--..",
"0"=>"-----",
"1"=>".----",
"2"=>"..---",
"3"=>"...--",
"4"=>"....-",
"5"=>".....",
"6"=>"-....",
"7"=>"--...",
"8"=>"---..",
"9"=>"----.",
"."=>".-.-.-",
","=>"--..--",
"?"=>"..--..",
"/"=>"-..-.",
" "=>" ");
foreach ( $possibilities as $key => $value ) {
if( $value == $criteria ){
array_push( $possible_match , $key );
}
}
return $possible_match;
}
this is pretty standard is all criteria where string like
find_possible_match( ".-" );
will return [a]... etc
but the twist is that, what if the params has an unknown, example
find_possible_match("?");
should return [e, t], likewise
find_possible_match("?.")
should return ['i','n'] and
find_possible_match(".?")
should return ['i','a']
? in this case is the wildcard. How do i modify the above code to do just that. Thank you