gpt4 book ai didi

php - php数组中的奇怪错误

转载 作者:行者123 更新时间:2023-12-04 00:36:17 25 4
gpt4 key购买 nike

我正在尝试对数组进行 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com