亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如下內容,關于php的end函數問題,該怎么解決?

如下內容,關于php的end函數問題,該怎么解決?

PHP C
慕村9548890 2022-04-15 11:11:53
錯誤:<?php$str="milu.jsp";$filetype=end(explode(".",$str)); echo $filetype;?>正確:<?php$str="milu.jsp";$filetype=explode(".",$str); echo end($filetype);?> 期待傳說中的高手現身解釋
查看完整描述

2 回答

?
慕娘9325324

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版本好像都可以了.



查看完整回答
反對 回復 2022-04-19
?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

這兩個結果都是對的。
<?php$str="milu.jsp";$filetype=end(explode(".",$str)); echo $filetype;?> 分號回車:
<?php
$str="milu.jsp";
$filetype=end(explode(".",$str));
echo $filetype;
?>

都是對的,為什么要問這個問題



查看完整回答
反對 回復 2022-04-19
  • 2 回答
  • 0 關注
  • 172 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號