php 错误:unexpected '$staff'

WBOY
发布: 2016-06-06 20:21:27
原创
1441 人浏览过

这是源码:

<code><?php header("Content-Type:text/plain;charset=utf-8")

$staff = array
    (
        array("name" => "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 "<h1>error</h1>";
        return;
    }
    echo "The person".$_POST["name"]."save success";
}

 ?>
 </code>
登录后复制
登录后复制

然后报错:
Parse error: syntax error, unexpected '$staff' (T_VARIABLE) in D:\wamp\www\test\query.php on line 4

回复内容:

这是源码:

<code><?php header("Content-Type:text/plain;charset=utf-8")

$staff = array
    (
        array("name" => "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 "<h1>error</h1>";
        return;
    }
    echo "The person".$_POST["name"]."save success";
}

 ?>
 </code>
登录后复制
登录后复制

然后报错:
Parse error: syntax error, unexpected '$staff' (T_VARIABLE) in D:\wamp\www\test\query.php on line 4

$staff前,header()这行没有用分号;结束。语法错误。
21和36行也有
新手用个ide比较好。

改为这样:

<code><?php header("Content-Type:text/plain;charset=utf-8");

$staff = array
    (
        array("name" => "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"),
    );</code>
登录后复制

22 行 和 36行也有错误

相关标签:
php
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板