PHP: Returning values - Manual in Deutsh
PHP: Returning values - Manual in French
PHP: Returning values - Manual in Polish

You Are At PHP: Returning values - Manual Area


recent searches:
include functions , variable functions , post functions...




If you are new to PHP or just need to refresh your skills, this is the place to start. This series of tutorials will give you the basic knowledge you will need to create a simple PHP website.

PHP is a reflective programming language originally designed for producing dynamic web pages.[1] PHP is used mainly in server-side scripting, but can be used from a command line interface or in standalone graphical applications. Textual User Interfaces can also be created using ncurses.

PHP Manual
PrevChapter 17. FunctionsNext

Returning values

Values are returned by using the optional return statement. Any type may be returned, including lists and objects. This causes the function to end its execution immediately and pass control back to the line from which it was called. See return() for more information.

Example 17-11. Use of return()

<?php
function square($num)
{
    return
$num * $num;
}
echo
square(4);   // outputs '16'.
?>

You can't return multiple values from a function, but similar results can be obtained by returning a list.

Example 17-12. Returning an array to get multiple values

<?php
function small_numbers()
{
    return array (
0, 1, 2);
}
list (
$zero, $one, $two) = small_numbers();
?>

To return a reference from a function, you have to use the reference operator & in both the function declaration and when assigning the returned value to a variable:

Example 17-13. Returning a reference from a function

<?php
function &returns_reference()
{
    return
$someref;
}

$newref =& returns_reference();
?>

For more information on references, please check out References Explained.

Numizmatyka
Agencja Reklamowa Katowice
analizy
banki kredyty
salon

Another Useful functions:


zend.returning | zend-macro.return-zval | zend-macro.return-unicodel | zend-macro.return-unicode | zend-macro.return-u-stringl | zend-macro.return-u-string | zend-macro.return-textl | zend-macro.return-text | zend-macro.return-stringl | zend-macro.return-string | zend-macro.return-rt-stringl | zend-macro.return-rt-string | zend-macro.return-resource | zend-macro.return-null | zend-macro.return-long | zend-macro.return-empty-unicode | zend-macro.return-empty-string | zend-macro.return-empty-binary | zend-macro.return-double | zend-macro.return-bool | zend-macro.return-binaryl | zend-macro.return-binary | zend-macro.return-ascii-stringl | zend-macro.return-ascii-string | language.references.return | functions.returning-values | function.runkit-return-value-used | function.return | function.m-returnstatus | function.ccvs-return |


PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. If you are new to PHP and want to get some idea of how it works, try the introductory tutorial. After that, check out the online manual, and the example archive sites and some of the other resources available in the links section.