Blogger Information
Blog 22
fans 0
comment 0
visits 15605
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
函数的返回值,参数
杰西卡妈妈
Original
1814 people have browsed it

1. 函数的返回值return

  1. 函数只能返回单个值,返回值的数据类型可以是任意类型.函数不能返回多个值,但可以通过返回一个数组来得到类似的效果
  2. 函数碰到return语句,立即结束程序执行,return后面的代码不会被执行
    3.如果没有return,返回的就是null

    code:

    <?php
    function a($b);
    {
    return $b + $b;
    }
    echo a(2);

输出的结果是: 4

<?php
function numbers();
{
return array (2,3,4,5);
}
list ($two,$three,$four,$five)=numbers();
echo ‘<pre>‘;
print_r(numbers());

输出的结果是:
Array
(
[0] => 2
[1] => 3
[2] => 4
[3] => 5
)

2. parameters 函数的参数

函数参数的作用:

  • 1.没有参数时, 执行的任务是固定的
  • 2.有参数,可以根据用户传递过来的数据决定函数内的程序该如何执行,函数的参数列表是给用户调用函数的时候,提供的接口
    function createTable(int $rows, int $cols)
    {
    $table = “<table border='1' cellspacing='0'>“;
    for ($i=0; $i < $rows ; $i++) {

    1. $table .= "<tr>";
    2. for ($j=0; $j < $cols; $j++) {
    3. $table .= "<td>parameter</td>";
    4. }
    5. $table .= "</tr>";

    }
    $table.=”</table>“;

    return $table;
    }

echo createTable(9,6);

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post