如果函數validateCustomForm()
不返回任何內容,則表示所有變量均已設置。我嘗試使用empty()
,但我想,因爲在函數中有東西會一直返回false。檢查函數是否返回
如何檢查一個函數是否返回一些東西?
<?php
function validateCustomForm(){
$os0 = "";
$os1 = "5";
$os2 = "6";
$os3 = "5";
if(!empty($os0)){
//do nothing
}else{
$w = "width is missing";
echo $w;
}
if(!empty($os1)){
//do nothing
}else{
$h = "height is missing";
echo $h;
}
if(!empty($os2)){
//do nothing
}else{
$c = "color is missing";
echo $c;
}
if(!empty($os3)){
//do nothing
}else{
$q = "qty is missing";
echo $q;
}
}//end function
$valid = validateCustomForm();
if(!empty($valid)){
echo "something is missing";
} else{
echo "all good";
}
?>
刪除'echo' S,只返回一個值顯示或者空,否則,還是假的,如果你喜歡 – 2014-09-04 04:21:29
我看不出有什麼'return'語句,以便'$ valid'永遠是'void' ('null') – Phil 2014-09-04 04:21:42
當你談論'return'時,你的函數中必須有'return'聲明 – codepixlabs 2014-09-04 04:25:19