How can I define integer inputs to a function and get array as an output?
Defining the array in phi() returns a pointer to unassigned memory - it is no longer reserved once phi() returns. The next function call or interrupt (which you have no control over) will likely clobber the data.

A better choice would be to define z in the caller (loop() in this case) as an uninitialized array and pass it to phi() to fill and return. This is the more usual case, as it:


avoids using globals, 
permits multiple calls to the function without clobbering previously returned data (you would pass different arrays in this case), and
it avoids statically defined arrays that may not be needed after the caller returns, in a memory-starved environment (this may not be applicable if loop() is the caller).


In short, it gives the calling function the greatest flexibility, while committing the least amount of memory.