Find one extra character in a string | PHP program to find extra character in one string ; result store the result ; traverse string A till end and xor with res ; xor with res ; traverse string B till end and xor with res ; xor with res ; print result at the end ; given string
< ? php function findExtraCharcter ( $ strA , $ strB ) { $ res = 0 ; for ( $ i = 0 ; $ i < strlen ( $ strA ) ; $ i ++ ) { $ res ^= ord ( $ strA [ $ i ] ) ; } for ( $ i = 0 ; $ i < strlen ( $ strB ) ; $ i ++ ) { $ res ^= ord ( $ strB [ $ i ] ) ; } return $ res ; } $ strA = " abcd " ; $ strB = " cbdad " ; echo chr ( findExtraCharcter ( $ strA , $ strB ) ) ; ? >