x_maras
x_maras

Reputation: 2217

How to merge multidimensional arrays in php

I have the following case in php

$one = array('one' => 1,  2 => array('intro'=> 'something', 'short' => 'short')); 
$two = array('intro' => 'something_new');
$three = array_merge($one,$two);

what I wanted to do is to change the one[2][intro] to two[intro] what it does is append the "two" array into the "one"

How I could change the value of the first array with the second ones by knowing only the key but not in which level is this key?

Upvotes: 1

Views: 1042

Answers (2)

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76870

You could do

$one[2] = array_merge($one[2],$two);

Upvotes: 3

Dr.Kameleon
Dr.Kameleon

Reputation: 22810

What about :

$new_two = array_merge($one[2],$two)
$one[2] = $new_two;

Upvotes: 4

Related Questions