「PHP入門」参照渡しの引数のサンプルコード
構文
function 関数名( &引数変数名 ) {
// some code
}
サンプルコード
<?php
function testFunc(&$x) {
return ++$x;
}
$y= 20;
echo testFunc($y) ."<br>\n";
echo $y ."<br>\n";
?>
<?php
function testFunc(&$x) {
return ++$x;
}
$y= 20;
echo testFunc($y) ."<br>\n";
echo $y ."<br>\n";
?>
<?php function testFunc(&$x) { return ++$x; } $y= 20; echo testFunc($y) ."<br>\n"; echo $y ."<br>\n"; ?>
実行結果
21
21