user3322610
user3322610

Reputation: 39

php adding 2 arrays into same session array

$firstarray = array(
  'name'=>$name,
  'address'=>$address
);

$_SESSION['info'] = $firstarray;

$secondarray = array(
  'postcode'=>$postcode,
  'email'=>$email
);

$_SESSION['info'] = $secondarray;

Hi guys, how do I add the array into session info without overwrite its value which are already inside? I want the session info contain the value of firstarray and second array all together.

Upvotes: 0

Views: 74

Answers (1)

xdazz
xdazz

Reputation: 160833

Use array_merge:

$_SESSION['info'] = array_merge($_SESSION['info'], $secondarray);

Upvotes: 1

Related Questions