duangu1033 2011-04-20 12:55
浏览 51
已采纳

php数组中的奇怪错误

I am trying to json encode an array,it does encode but i get lots of errors:

$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);

I get the following errors.

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
  • 写回答

6条回答 默认 最新

  • dr200166 2011-04-20 12:56
    关注

    You need to quote the keys. Without quotes, they're constants. The interpreter is guessing what you mean, but you should change it to avoid the notice.

    $products = array( array( "Title" => "rose", 
                      "Price" => "1.25,1.31,1.54,1.39",
                      "Type" => "dropdown"
                    ),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。