can I put a function in PHP inside a if structure? like this:
Basically yes, according to the manual:
Any valid PHP code may appear inside a function, even other functions and class definitions.
Personally I haven't had a situation in which I'd actually do such a thing. Most of the time it would be easier to group your functions on a place where it actually can be found! ;-)