can I put a function in PHP inside a if structure? like this:
As middaparka says, this is perfectly legal, but in terms of using it, you might want to check if a function exists before declaring it:
if (!function_exists("foo")) { function foo() { return "bar"; } }