PHP Questions Home
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I return a value from a function?


The clue is in the question - you use the keyword 'return'.

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
?>



ASK A QUESTION

More functions PHP Questions

WHAT IS THE CORRECT WAY TO OPEN THE FILE "time.text" AS READABLE?

What is a static variable within a function?

what is var_dump function in php?

I am currenly trying to translate a language-file (english.php to norwegian.php) But I have run across something strange: In the middle of the file, there is a line with: ?>

Hi; I had an email from my hosting company which said that my account was hacked and one script in images folder is trying to send thousands of spams(file name : "/public_html/images/sm5vy7.php"). they blocked my account and asked me to check



Custom Search