簡體   English   中英

為什么PHP雙箭頭運算符'=>'停止執行代碼

[英]Why does the PHP double arrow operator '=>' stop the execution of the code

我正在嘗試創建一個Web應用程序,並且想要創建鍵值對數組。 像這樣:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"></meta>
  <link rel="stylesheet" type="text/css" href="css/style.css">
  <title></title>
  <script type="text/javascript" charset="utf-8" src="lib/jquery-1.11.0.js"></script>
  <script type="text/javascript" charset="utf-8" src="script/main.js"></script>
</head>


<?php

$data = array('grant_type' => $authorization_code);

// more code goes here

?>

  <div class="container">

  </div>

</body>

</html>

由於某種原因,上面的代碼僅顯示$ authorization_code); //更多代碼在這里?>

因此,似乎每次我在代碼中插入“ =>”時執行都會停止。 即使注釋了'=>',也會發生這種情況。

在拒絕投票之前,請考慮一下我已經感到難以置信,而且我真的,真的沒有找到Googling對此的答案。

編輯

添加了完整的源代碼。

您沒有引用任何一個值,因此PHP會將它們視為未定義的常量

嘗試

$data = array('grant_type' => $authorization_code);

或實際上應該是什么。

php > $data = array(foo => bar);
PHP Notice:  Use of undefined constant foo - assumed 'foo' in php shell code on line 1
PHP Notice:  Use of undefined constant bar - assumed 'bar' in php shell code on line 1
php > define('foo', 'hello');
php > define('bar', 'world');
php > $data = array(foo => bar);
php > var_dump($data);
array(1) {
  ["hello"]=>
  string(5) "world"
}

就停止執行而言, =>不應是PHP塊的哨兵值。 只有?>會“關閉” php。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM