How do I return a value from a function?
The first time you create a function you might do something like this and get confused:
<?php
$value = 20;
function timestwo($value) { $result = $value * 2; }
$doubled = timestwo($value);
echo "$value doubled is $doubled";
//prints: 20 doubled is
?>
... and you get no value! That's because you need to use 'return' in the function, and it then works:
<?php
$value = 20;
function timestwo($value) { $result = $value * 2; return $result; }
$doubled = timestwo($value);
echo "$value doubled is $doubled";
//20 doubled is 40
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More functions PHP Questions
Is there a way to use readfile() and not have it display the byte number at the bottom?How can I call online a PHP function. It works local but when I put it online it does nothing. I call online a php function to load pictures into my flex application. Thanks Bart
how to create a search engine
I have used the funtion Rate (code below) and i have some troubles with it. When i use it with the following values: (Wrong) Excel - RATE(228;-196,02;-49005;961546,464646;1;0,05) gives: 0,0119 Php - RATE(228,-196.02,-49005,961546.464646,1,0.05) gives
how can i get the data by using get(),post()methods?
