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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么