php 错误:unexpected '$staff'
程序员文章站
2022-05-07 15:24:58
...
这是源码:
"x","number" => "101","sex" => "male","job" => "manager"),
array("name" => "y","number" => "102","sex" => "male","job" => "manager"),
array("name" => "z","number" => "103","sex" => "male","job" => "manager"),
);
if ($_SERVER["REQUEST_METHOD"] == "GET") {
search();
}elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
create();
}
function search() {
if (!isset($_GET["number"]) || empty($_GET["number"])) {
echo "error";
return;
}
global $staff
$number = $_GET["number"];
$result = "error";
foreach ($staff as $key => $value) {
if ($value["number"] == $number) {
$result = "The person's ID is".$value["number;"]."He's name is".$value["name;"]."And sex is".$value["sex"]."The job".$value["job"];
break;
}
}
echo $result;
}
function create() {
if (!isset($_POST["name"]) || empty($_POST["name"]) ||
!isset($_POST["number"]) || empty($_POST["number"]) ||
!isset($_POST["sex"]) || empty($_POST["sex"]) ||
!isset($_POST["job"]) || empty($_POST["job"]) {
echo "error
";
return;
}
echo "The person".$_POST["name"]."save success";
}
?>
然后报错:
Parse error: syntax error, unexpected '$staff' (T_VARIABLE) in D:\wamp\www\test\query.php on line 4
回复内容:
这是源码:
"x","number" => "101","sex" => "male","job" => "manager"),
array("name" => "y","number" => "102","sex" => "male","job" => "manager"),
array("name" => "z","number" => "103","sex" => "male","job" => "manager"),
);
if ($_SERVER["REQUEST_METHOD"] == "GET") {
search();
}elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
create();
}
function search() {
if (!isset($_GET["number"]) || empty($_GET["number"])) {
echo "error";
return;
}
global $staff
$number = $_GET["number"];
$result = "error";
foreach ($staff as $key => $value) {
if ($value["number"] == $number) {
$result = "The person's ID is".$value["number;"]."He's name is".$value["name;"]."And sex is".$value["sex"]."The job".$value["job"];
break;
}
}
echo $result;
}
function create() {
if (!isset($_POST["name"]) || empty($_POST["name"]) ||
!isset($_POST["number"]) || empty($_POST["number"]) ||
!isset($_POST["sex"]) || empty($_POST["sex"]) ||
!isset($_POST["job"]) || empty($_POST["job"]) {
echo "error
";
return;
}
echo "The person".$_POST["name"]."save success";
}
?>
然后报错:
Parse error: syntax error, unexpected '$staff' (T_VARIABLE) in D:\wamp\www\test\query.php on line 4
$staff
前,header()这行没有用分号;
结束。语法错误。
21和36行也有
新手用个ide比较好。
改为这样:
"x","number" => "101","sex" => "male","job" => "manager"),
array("name" => "y","number" => "102","sex" => "male","job" => "manager"),
array("name" => "z","number" => "103","sex" => "male","job" => "manager"),
);
22 行 和 36行也有错误
推荐阅读
-
nginx加php-fpm出现502 bad gateway错误的5种解决方法
-
Nginx PHP-Fcgi中因PHP执行时间导致504 Gateway Timeout错误解决记录
-
php一些错误处理的方法与技巧总结
-
php session_start()关于Cannot send session cache limiter - headers already sent错误解决方法
-
php编译安装常见错误大全和解决方法
-
PHP异常Parse error: syntax error, unexpected T_VAR错误解决方法
-
ThinkPHP调用common/common.php函数提示错误function undefined的解决方法
-
配置php网页显示各种语法错误
-
实现Nginx中使用PHP-FPM时记录PHP错误日志的配置方法
-
Ubuntu 14.04 下开启PHP错误提示