你好我只是測試的東西,理解概念通串入功能爲2個或更多參數
我嘗試這樣做:
$args = "'file.txt', 'w'";
fopen($args);
但FOPEN將其視爲一個參數
什麼時我錯過了?
你好我只是測試的東西,理解概念通串入功能爲2個或更多參數
我嘗試這樣做:
$args = "'file.txt', 'w'";
fopen($args);
但FOPEN將其視爲一個參數
什麼時我錯過了?
在PHP 5.6,你可以使用argument unpacking這在我看來是最接近你嘗試過什麼:
$args = ['file.txt', 'w'];
fopen(...$args);
你不能像這樣傳遞參數。做到這一點的方法是如下:
<?
$args = array("file.txt","w");
$fopen($args[0],$args[1]);
?>
你要做的就是創建一個什麼字符串,它是「‘file.txt的’,‘W’」,並提交作爲一個參數。
見fopen()
方法簽名:
的fopen(字符串$文件名,字符串$模式[,布爾$ use_include_path = FALSE [,資源$背景]])
你想要什麼做的是:
$file = 'file.txt';
$mode = 'w';
fopen($file, $mode);
如果你打開一個文件,所以有些書面它,爲什麼不使用file_put_contents
- 這可能是更容易使用。
你應該把2個參數fopen()函數
<?
$args = array("file" => "file.txt",
"option" => "w");
fopen($args["file"],$args["option"]);
?>
你不能做到這一點,正確的做法是使用兩個變量 – adeneo 2015-03-19 12:59:08
你有一個特定的原因,你爲什麼要這麼做? – Ghost 2015-03-19 13:00:09
其他的(醜陋的)選項就像是'call_user_func_array(fopen,array('file.txt','w'))' – adeneo 2015-03-19 13:00:11