雖然我練了PHP我想打一個函數在PHP for
環功能的PHP for循環
function Yearsbox(,) {
for ($i=2000; $i < 2020 ; $i++) {
echo $i;
}
}
echo Yearsbox;
有什麼不對?
雖然我練了PHP我想打一個函數在PHP for
環功能的PHP for循環
function Yearsbox(,) {
for ($i=2000; $i < 2020 ; $i++) {
echo $i;
}
}
echo Yearsbox;
有什麼不對?
您可能不會將一個逗號作爲該函數的參數。請給你的參數一個有效的名字或者把括號留空。
其次,你打電話與支架功能(忘了我以前寫的,你必須添加它們,否則PHP解釋爲常數)
這是應該工作:
function Yearsbox() {
for ($i=2000; $i < 2020 ; $i++) {
echo $i;
}
}
Yearsbox();
爲什麼要低估我?不要downvote w/o告訴爲什麼... –
首先你必須定義這個函數,如果你想從中獲取數據,就讓它返回一些數據。然後,你調用這個函數。你的情況:
<?php
function Yearsbox() {
for ($i=2000; $i < 2020 ; $i++) {
echo $i;
}
}
Yearsbox();
OR:
<?php
function Yearsbox() {
$output = "";
for ($i=2000; $i < 2020 ; $i++) {
$output .=$i;
}
return $output;
}
echo Yearsbox();
或者你也可以使用兩種可選的參數組合:
<?php
function Yearsbox($echo=false) {
$output = "";
for ($i=2000; $i < 2020 ; $i++) {
$output .=$i;
}
if($echo){
echo $output;
return null;
}
return $output;
}
echo Yearsbox();
請再次閱讀功能手冊 - HTTP:// PHP .net/manual/en/functions.user-defined.php –
'Yearsbox(,)'是錯誤的,它是無意義的,而且無效的語法 –
這個逗號在param列表中是什麼意思? – halfer