linux1880 Posted January 6, 2010 Share Posted January 6, 2010 hi friends I want to redirect to a different page after few statements in function, how do i achieve this ? also, how important is RETURN for function ? pls help Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted January 6, 2010 Share Posted January 6, 2010 Providing you haven't output anything to the browser, just edit your function to redirect after the statements you want have been executed, like so: <?php function myFunction() { echo 'some statements'; header("Location: newLocation.php"); echo "these won't be shown as you have been re-directed at the line above"; } ?> As for return, you only use that if you want the function to return a value to a variable. Example: <?php function updateName($name) { return $name . " rocks"; } $myName = "PHP Monkeh"; $newName = updateName($myName); echo $newName; // echo 'PHP Monkeh rocks' ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.