06c06-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 30 行

PHP
30
字号
<?php// Define a function that will increment a variable by 2, and returns a //  copy of the new value.  Similar to the ++ operator, but going by 2//  at a time.function add2(&$number) {    $number += 2;    return $number;}// Use this to add 2 to a number, storing the output.$mynum = 5;$output = add2($mynum);// Now add one to the $output variable and echo out the values://   output = 8, mynum = 7$output++;echo "<p>output = {$output}, mynum = {$mynum}</p>\n";// Define a function that will initialize a 10 by 10 array, and//  return a reference to it:function &initialize() {    $new = array_fill(0, 10, array_fill(0, 10, 0));    return $new;}// Initialize a new array with this, and echo it out:$newarray =& initialize();echo '<pre>', print_r($newarray, true), '</pre>';?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?