在php中使用未定义的常量错误

问题描述:

以下代码

<?php
 $email_domain = "abc@gmail.com";
 $email_user = "Roshan";
 $email_pass = "admin";
 $email_quota = "200";
 $call = array(domain=>$email_domain, email=>$email_user, password=>$email_pass, quota=>$email_quota);

 echo json_encode($call);
?>

产生以下错误:

Notice: Use of undefined constant domain - assumed 'domain' in C:\xampp\htdocs\test2.php on line 7

Notice: Use of undefined constant email - assumed 'email' in C:\xampp\htdocs\test2.php on line 7

Notice: Use of undefined constant password - assumed 'password' in C:\xampp\htdocs\test2.php on line 7

Notice: Use of undefined constant quota - assumed 'quota' in C:\xampp\htdocs\test2.php on line 7
{"domain":"abc@gmail.com","email":"Roshan","password":"admin","quota":"200"}

我想知道这种情况的发生,以及在这种情况下可以采取哪些措施来防止出现此错误.

I want to know the occurrence of this and in this case what can be done to prevent this error.

array(name => value) is not a valid syntax, php 现在没有什么 name代码>是.您需要在数组键周围加上引号.

array(name => value) is not a valid syntax, php doesn't now what name is. You need quotation marks around your array keys.

使用 array("domain" => $email_domain, ...