2 回答

TA貢獻1783條經驗 獲得超4個贊
不知道你的php是什么版本?
我在php5.2.14下運行,沒有錯誤提示
要注意的就是end函數的用法:mixed end ( array &array )
end的參數是一個引用,你可以參考手冊end函數下面的一個用戶的說明:
ken at expitrans dot com
28-Oct-2005 12:02
Please note that from version 5.0.4 ==> 5.0.5 that this function now takes an array. This will possibly break some code for instance:
<?php
echo ">> ".end(array_keys(array('x' => 'y')))."\n";
?>
which will return "Fatal error: Only variables can be passed by reference" in version <= 5.0.4 but not in 5.0.5.
If you run into this problem with nested function calls, then an easy workaround is to assign the result from array_keys (or whatever function) to an intermediary variable:
<?php
$x = array_keys(array('x' => 'y'));
echo ">> ".end($x)."\n";
?>
如果你的php版本是早期的,那么php可以自動把$filetype視為引用,傳遞給end函數.所以第二種寫法是正確的.第一種就可能會提示:只有變量可以作為引用傳遞,而函數的返回值不可以動態的作為引用傳遞.
現在的php版本好像都可以了.

TA貢獻1966條經驗 獲得超4個贊
這兩個結果都是對的。
<?php$str="milu.jsp";$filetype=end(explode(".",$str)); echo $filetype;?> 分號回車:
<?php
$str="milu.jsp";
$filetype=end(explode(".",$str));
echo $filetype;
?>
都是對的,為什么要問這個問題
- 2 回答
- 0 關注
- 172 瀏覽
添加回答
舉報