function processSetup($mac, &$s20Table, $actionValue) { if ($actionValue == "procSetup") { $oldName = $s20Table[$mac]['name']; if (isset($_POST["newName"])) { $newName = $_POST["newName"]; if ($newName != $oldName) { $newName = setName($mac, $newName, $s20Table); if ($newName != "") { $s20Table[$mac]['name'] = $newName; $_SESSION['s20Table'] = $s20Table; writeDataFile($s20Table); } } } $nnext = (int) $_POST['numberOfNextEvents']; $s20Table[$mac]['next'] = $nnext; writeDataFile($s20Table); $_SESSION['s20Table'] = $s20Table; } else { if ($actionValue == "procSetupCancel") { // OK, nothing here } else { if ($actionValue == "procSetupDel") { unset($s20Table[$mac]); writeDataFile($s20Table); $_SESSION['s20Table'] = $s20Table; } else { error_log("process setup: unknow action: >" . $actionValue . "<\n"); } } } }
//include('a.php');//遇到既包含 //include_once('a.php');//判断是否包含 //include和require的区别:include失败触发warning require出错终止程序 //我们应当使用require_once //函数执行:php开辟新栈 各个栈间变量相互独立 //函数参数类型:array int float bool string object null 资源类型 //函数开头字母:_ a-z A-Z //函数名不区分大小写 自定义函数中变量是局部的,函数外不生效 $a = 2; function setName() { global $a; $a = 1; echo '$a=' . $a; } setName(); echo $a; //php中三种提示: notice warning error //global全局变量可以使用外部变量 //在函数中,我们不希望使用某个变量,或者是彻底的不在使用某个变量,可以使用unset($a);将该变量彻底删除 //函数默认值的问题:($a = 2){echo $a;}//2 //php默认值传递,需要地址传递可以使用&变量名 //常量:不需要$ //不能修改,需要赋初值,define or const ,全部大写用下划线间隔,不需要值变化,考虑使用常量 define('_NAME_', 'my name'); const _NAME_ = 'my name'; //数组:关键字和值得组合,值可以使任意类型 //array('1'=>1,'2'=>2); 下标可以自己指定 //$arr['logo'] = 'logo'; $arr[0] = 1; $arr[1] = 1;
<div id="contact-email" class="content"><h2>E-mail</h2> <form id="hire" method="POST" action="<?php htmlspecialchars($_SERVER["PHP_SELF"]); ?> "> <div class="field name-box"> <input type="text" id="name" name="name" value="<?php echo $name; ?> " placeholder="Greetings" required /> <label for="name">Name*</label> <span class="glyphicon-ok"></span> <span class="error"><?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = setName($_POST["name"]); } ?> </span> </div> <div class="field email-box"> <input type="text" type="email" id="email" name="email" value="<?php echo $email; ?> " placeholder="*****@*****.**" required /> <label for="email">Email*</label> <span class="glyphicon-ok"></span> <span class="error"><?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $email = setEmail($_POST["email"]);
function __construct() { setName(); setUsername(); setPassword(); }
public function getClasses() { return $this->classes; } private function setFName($name) { $this->fname = $name . ' - ' . get_class($this); } } // Prove the polymorphism by calling a member function function setName(Person $person, $name) { $person->setFirstName($name); } function showDetail(Person $person) { $name = $person->getFirstName(); return "This person's name is {$name}"; } // Test the inheritance/polymorphism $s1 = new Student('Dave', array('English' => 74, 'Maths' => 46, 'Science' => 65)); $t1 = new Tutor('Mike', array('Maths', 'Science')); $t2 = new Tutor('Chris', array('English', 'History')); setName($s1, 'Peter'); setName($t2, 'Mike'); echo '<br />'; echo showDetail($s1); echo '<br />'; echo showDetail($t1); echo '<br />'; echo showDetail($t2);