私は文字列を持っており、次のように2つのキーを持つ配列も持っています:
$string = "black"; // a string that has 5 characters
$array = array(0=>"c", // an array that has two keys "c" and "b"
1=>"b")
要件:
配列の最初のキー値を文字列のすべての文字と繰り返して比較し、次に配列の2番目のキー値を文字列のすべての文字と比較するループが必要です。
キーが文字列の文字と一致する場合は文字列文字を印刷し、そうでない場合はスター(*)を印刷します。このようなもの:
if($string[$character] == $array[$key]){
echo $string[$character];
}
else{
echo "*";
}
//So in this case, Final Output should be:
// Final Output = b**c*
最終出力を達成するためにどのようにアプローチできますか?