我正在與php函數作鬥爭。PHP中的函數
我想創建一個接受5個參數的函數。 用戶需要選擇他們選擇的活動,他們選擇的活動的消息應該回顯給用戶。
我在函數中使用了一個數組和一個foreach語句,但它不起作用。
請幫
<?php
// Declare the function and variables
error_reporting (0);
$msg = "";
$activity = "";
function activites ($paintballing , $ice_skating, $horse_riding, $para_gliding, $water_rafting){
// Make the activity array
$activites = array (1=> 'Paintballing', 'Ice_skating', 'Horse_riding', 'para_gliding', 'water_rafting');
// make the activity pull down menu
echo '<select name ="activity">';
// use a foreach loop to loop through the activity
foreach ($activites as $key =>$value) {
echo "<option value \"key\"$key\">$value</option>\n";
}
}
if ($activity == ""){
$msg = "<font color = 'red'> Please select an activity from the drop down menu</font>";
}
?>
<html>
<head>
<title>Function </title>
</head>
<body>
<center> <a href="index.php">Home </a> | <a href ="calc.php">Calc</a> | <a href="string.php">String</a> | <a href ="array.php"> Array </a> | <a href = "function.php">Function </a></center>
</center>
<form name = 'function' method = "POST" action = 'function.php' >
<p>Select one of the activity you would like to do today:</p>
<select name="Activity" size="5">
<option selected value = "">
<option> Paintballing </option>
<option> Ice-skating </option>
<option> Horse-riding </option>
<option> Para-gliding </option>
<option> Water-rafting </option>
</select>
</form>
<input type = "submit" name = "submit" value = "submit" />
</option>
<?php echo $msg;?>
<p align ="center"><a href ="function.txt" Onclick ="window.open ('function.txt', 'function', resizable =no, height=500, width=500, scrollercars=yes'); retrun false;">Function.txt</a></p>
什麼是你的錯誤消息的功能? – 2013-03-22 18:02:04
'$ activites = array(1 => $ paintballing,$ ice_skating,$ horse_riding',$ para_gliding',$ water_rafting');' – 2013-03-22 18:03:09
你真的在某處調用這個函數嗎? – ioums 2013-03-22 18:04:20