How do i set global variable in a function in wordpress functions.php

Declare $a as a global variable, just as you have with $post:

global $post, $a;

(Keep in mind, you may collide with other variables, since your var name is not really all that unique)