/**
* 參數數組$ParamList說明
*
* 數組的第一個維索引是需要測試的函數的參數名,第二維的每個元素是該參數需要測試的可能值,元素值可以為數組。
*/
$ParamList = array("Param1" => array(3,4,3,2,1),
,5),
"Param3" => array(0,0.5,1,1.5));
// 測試函數est函數
function Test($Param1, $Param2, $Param3)
return $Param1 . "|" . $Param2 . "|" . $Param3;
}
/**
* 自動測試
* @param array $ParamList 參數清單
* @return array */ FunctionName, $ParamList)
{
if(empty($FunctionName))
{
if(!is_array(current($ParamList)))
{
echo "參數不是2維數組";
return false;
}
ParmListaaParamList 開始測試函數$FunctionName . "
";
foreach($ TestParamList as $Key => $TestParamInfo)
{
foreach($TestParamInfoas $ParamKey => $Param)
{
$TempParamList[] = "$Param" . $ParamKey;
if(is_array($Param ))
{
echo "參數
";<br> {<br> echo "參數" . $ParamKey . ",類型為boll:";<br> if($Param)<br> {<br> echo "true";<br> }<br> else<br> {<br> echo "false";<br> }<br> }<br> else<br> { <br> echo "參數" . $ParamKey . ",類型為字串或數字:";<br> }<br> echo "<br>";<br> }<br><br> TempParamList);<br> unset($TempParamList);<br><p> eval("$TestReturnResult = " . $FunctionName . "(" . $Params . ");");<br> echo "函數傳回陣列:</p><pre class="brush:php;toolbar:false">";<br> print_r ($TestReturnResult);<br> }<br> elseif(is_bool($TestReturnResult } else<br> {<br> echo " <br> }<br> else<br> {<br> }<br> echo "<br><br>";<br> }<br>}<br><br>/**<br> * 計算組合的函數<br> *<br> * @param array $CombinList 待排列組合的2維陣列<br> * @return array */ <br>function sysCombineArray($CombinList)<br>{<br> if(!is_array(current($CombinList)))<br> { }<p><br> /* 計算C(a,1 ) * C(b, 1) * ... * C(n, 1)的價值*/<br> $CombineCount = 1;<br> foreach($CombinListas $Key => $ ($Value);<br> }<br><br> $RepeatTime = $CombineCount;<br> foreach($CombinListas $ClassNo => $ParamList) <br> $RepeatTime = $RepeatTime / count($ParamList);<br><br> $StartPosition = 1; {<br> $TempStartPosition = $StartPosition;<br></p> ParamList) / $RepeatTime;<p><br> for($I = 0; $I { <br> $Result[$TempStartPosition + $I][$ClassNo] = $Param; $TempStartPosition += $RepeatTime * count($ParamList);<br> }<br> }</p><p> return $Result;<br>}<br>?><br><br>以上就是測試php函數的程式碼,希望可以幫助大家更多相關內容請關注PHP中文網(www.php.cn)!</p>