【发布时间】:2021-11-27 02:48:48
【问题描述】:
我的数据库中保存了一个关联数组,我使用 Wordpress 函数 get_post_meta 将其保存到名为 response_cost 的变量中。
$response_cost = get_post_meta( $postID, $metaKey, true );
数组看起来像这样:
a:2: {
i:0;a:3:
{s:4:"type";s:6:"months";s:4:"cost";s:0:"";s:8:"modifier";s:1:"=";}
i:1;a:3:
{s:4:"type";s:5:"weeks";s:4:"cost";s:0:"";s:8:"modifier";s:1:"+";}
}
我创建了一个表单,它输出一个新数组并保存在一个名为 $add_to_response_cost 的变量中。
$add_to_response_cost = array (
'type' => $type,
'cost' => $cost,
'modifyer' => $modifyer
);
我不知道如何将 $add_to_response_cost 添加为 $response_cost 的另一个实例,以便输出结果如下:
a:3: {
i:0;a:3:
{s:4:"type";s:6:"months";s:4:"cost";s:0:"";s:8:"modifier";s:1:"=";}
i:1;a:3:
{s:4:"type";s:5:"weeks";s:4:"cost";s:0:"";s:8:"modifier";s:1:"+";}
i:2;a:3:
{ my new array I've constructed via $add_to_response_cost }
}
非常感谢任何帮助或指导。
【问题讨论】:
标签: php database wordpress associative-array