Debug!
For instance, if [font=courier new]some_function($x, $y)[/font] is not working, try adding some code to verify that the variables concerned are set to what you think they should be, and see what value the function is returning:
# DEBUG
echo "<p>DEBUG: x = $x</p>\n";
echo "<p>DEBUG: y = $y</p>\n";
# /DEBUG
$result = some_function($x, $y);
# DEBUG
echo "<p>DEBUG: result of some_function($x, $y): $result</p>\n";
# /DEBUG
Doing this sort of basic programming technique will often answer your question for yourself.