PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
The name doesn't explain well, but what I'm tying to achieve is probably a smack in the face when i get the answer. What I want is to be able to return a string from a function to be echoed out somewhere else on the page.
<?php
function myFunction($get) {
$get = $_GET['val'];
if($get!='defined_value') {
$msg = 'You are using the wrong value!';
} else {
$msg = 'You are using the correct value!';
}
}
return $msg;
?>
<?php
function myFunction() {
$get = $_GET['val'];
if($get!='defined_value') {
$msg = 'You are using the wrong value!';
} else {
$msg = 'You are using the correct value!';
}
return $msg;
}
?>
"Include" your php file and replace your text with the function call.
Although there really is no need for parentheses on the print call, the following would work the same and, considering how many times you use print/echo, will save lots of time in the long run.