简体   繁体   English

将关联数据插入php中的关联数据数组

[英]insert associative data to array of associative data in php

I'm trying to find out which is the correct way to add associative data to an array of associative data. 我正在尝试找出将关联数据添加到关联数据数组的正确方法。

I have something like this: 我有这样的事情:

$values = array('data1' => $data1, 'data2' => $data2, => 'data3' => $data3 );

now what if I want to add for example $data4 as 'data4' to $values? 现在,如果我想将$ data4作为'data4'添加到$ values,该怎么办?

Should I use array_merge() ? 我应该使用array_merge()吗?

like $values = array_merge($values, array('data4', $data4)); $values = array_merge($values, array('data4', $data4));

or is there a better / more correct way? 还是有更好/更正确的方法?

您可以保持简单:

$value['data4'] = $data4;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM