PHP求助?

来源:百度知道 编辑:UC知道 时间:2024/06/23 16:03:18
<?
$fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple");

function test_alter( $item1 ) {
$item1 = 'bogus';
}

function test_print( $item2 ) {
echo "$item2<br>\n";
}

array_walk( $fruits, 'test_print' );
array_walk( $fruits, 'test_alter' );
array_walk( $fruits, 'test_print' );
?>

test_alter这个函数好像没起作用?哪儿出了毛病?

function test_alter( $item1 ) {
$item1 = 'bogus';
}
//就这里没起作用,改为:〕
function test_alter(&$item1) {
$item1 = 'bogus';
}
//没有&怎么传地址呢?

我晕啊,老兄,你函数写错了啊。

PHP函数怎么能这么写呢?????你就没有返回值,肯定有毛病了哦。

应该是这样的

function test_alter(){
return "bogus";
}

PHP函数返回值要用return
你只是把个函数的局部变量赋了个值而已。
还有啊,这么个问题就给5分,哎~~~~~~~~~~~~~太小气了吧?

没有返回值