数组中的语法错误

时间:2018-06-16 16:14:22

标签: php arrays magento syntax

1-如果我这样写这条线;我使用的API(magento 2 rest api)不接受 category_ids 值:

$cat = '["34","22","14"]';
array( 'attribute_code' => 'category_ids', 'value' => $cat),

2-如果我写这样的行; API未再次保存 category_ids

array( 'attribute_code' => 'category_ids', 'value' => '["34","22","14"]'),

3-但如果我这样写;一切都很好:

array( 'attribute_code' => 'category_ids', 'value' => ["34","22","14"]),

我必须将 category_ids 值写为变量;那么,有人可以帮我写出正确的语法吗?

1 个答案:

答案 0 :(得分:0)

您不应将数组放在single quotes内。

// Change this
$cat = '["34","22","14"]';

// to this
$cat = ["34","22","14"];