php - php数组中的奇怪错误

标签 php arrays multidimensional-array

我正在尝试对数组进行 json 编码,它确实进行了编码,但出现了很多错误:

$products = array( array( Title => "rose", 
                      Price => "1.25,1.31,1.54,1.39",
                      Type => "dropdown"
                    ),
               array( Title => "daisy", 
                      Price => "0.75",
                      Type => "text_field",
                    ),
               array( Title => "orchid", 
                      Price => "1.15",
                      Type => "text_field"
                    )
             );
echo json_encode($products);

我收到以下错误。
Notice: Use of undefined constant Title - assumed 'Title' in C:\wamp\www\serializer.php on line 2

Notice: Use of undefined constant Price - assumed 'Price' in C:\wamp\www\serializer.php on line 3

Notice: Use of undefined constant Type - assumed 'Type' in C:\wamp\www\serializer.php on line 4

Notice: Use of undefined constant Title - assumed 'Title' in C:\wamp\www\serializer.php on line 6

Notice: Use of undefined constant Price - assumed 'Price' in C:\wamp\www\serializer.php on line 7

Notice: Use of undefined constant Type - assumed 'Type' in C:\wamp\www\serializer.php on line 8

Notice: Use of undefined constant Title - assumed 'Title' in C:\wamp\www\serializer.php on line 10

Notice: Use of undefined constant Price - assumed 'Price' in C:\wamp\www\serializer.php on line 11

Notice: Use of undefined constant Type - assumed 'Type' in C:\wamp\www\serializer.php on line 12

最佳答案

您需要引用键。没有引号,它们是常量。口译员正在猜测您的意思,但您应该更改它以避免通知。

$products = array( array( "Title" => "rose", 
                  "Price" => "1.25,1.31,1.54,1.39",
                  "Type" => "dropdown"
                ),

关于php - php数组中的奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5730651/

相关文章:

php - CodeIgniter 错误日志信息 + 错误

c++ - 指向特征矩阵的指针数组

c - 函数在 Release模式下崩溃,但在调试器中运行完美

c++ - 在 C++ 中使用指针访问多维数组元素

c++ - 指向类中多维数组的指针

php - 在 CakePHP 3.0 中将附加数据保存到联合表

javascript - 错误请求 :Error function and timeout in ajax never fired

php - 在表单中发布数组值时未获取数组值

python - 在 numpy 的 3 维矩阵中插入非对齐元素

php - 查找键的数组值