I presume those are just placeholders and not the actual values, because otherwise if you're just printing "x", literally, whenever each key matches $var, you could do:
foreach ($a_row as &$val) {
echo ($val == $var) ? 'x' : '';
}
Untested, but that ought to work as well. (For reference, uses a foreach() loop and the ternary operator.)