Chriz74
Chriz74

Reputation: 1480

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?

Should I use array_merge() ?

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

or is there a better / more correct way?

Upvotes: 0

Views: 28

Answers (1)

JazZ
JazZ

Reputation: 4579

You could keep it simple :

$value['data4'] = $data4;

Upvotes: 2

Related Questions