$string .= '<>add something extra.'; } $str = 'This is a string!'; add_some_extra($str); echo $str; ?> <!--在函数中使用默认参数--> <?php function makecoffee1($type = "cappuccino") { return "Making a cup of {$type}.\n"; } echo makecoffee1(); echo makecoffee1(null); echo makecoffee1("xudedong"), "<BR>"; ?> <!--PHP 还允许使用数组 array 和特殊类型 NULL 作为默认参数,使用非标量类型作为默认参数, 默认值必须是常量表达式,不能是诸如变量,类成员,或者函数调用等。--> <?php function makecoffee($types = array("aaaaa"), $coffeeMaker = NULL) { $device = is_null($coffeeMaker) ? "null" : "hands,{$coffeeMaker}"; return "Making a cup of " . join(",", $types) . " with {$device}.\n"; } echo makecoffee(), "<BR>"; echo 1.111111111111111E+27, "<BR>"; echo makecoffee(array("aaaaa", "bbbbb", "ccc"), 'ttt'); ?>
<?php define("BR", "</br>"); function add_some_extra(&$string) { $string .= 'и кое-что еще.'; } $str = 'Это строка, '; add_some_extra($str); echo $str; // выведет 'Это строка, и кое-что еще.' echo BR; function makecoffee1($type = "капуччино") { return "Готовим чашку {$type}.\n"; } echo makecoffee1(); echo makecoffee1(null); echo makecoffee1("эспрессо"); echo BR; function makecoffee($types = array("капуччино"), $coffeeMaker = NULL) { $device = is_null($coffeeMaker) ? "вручную" : $coffeeMaker; return "Готовлю чашку " . join(", ", $types) . " {$device}.\n"; } echo makecoffee(); echo makecoffee(array("капуччино", "лавацца"), "в чайнике");