Replace array value

The output of the array1 is looks as below.

Array ( [num_found] => 60 [articles] => 
Array ( [0] => 
Array ( [aut] => Array ( [0] => ANI ) [by] => ANI [Id] => 278 [key] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hydrogenated ) [norm] => true [body] => Gorging  [cat] => Array ( [0] => food & drink )
[pm] => ANI|P#M#D| [pm] => Beware! [seo] => junk [pmT] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hydrogenated ) [pid] => 72 [Date] => 2011-06-02T00:00:00Z [section] => Health [sd] => 3506926 [ti] => Beware! Junk food can cause miscarriage [ur] => riage [kick] => [subtitle] => [image] => [Tag] => ) 

[1] => Array ( [aut] => Array ( [0] => URVASHI ASHER ) [by] => URVASHI [Id] => 277 [key] =>
Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [norm] => true  [body] => division. [cat] => Array ( [0] => entertainment ) [pm] => URVASHI ASHER|P#M#D|TNN [pm] => booked [seo] => film [pmT] => Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [pid] => 72 [Date] => 2011-06-02T00:00:00Z [section] => News & Interviews [sd] => 3921796 [ti] => Amitabh booked [uri] => film [kick] => [subtitle] => [image] => [Tag] => )


I have a array2 similar to this.


Array ( [num_found] => 70 [articles] => 
Array ( [0] => 
Array ( [aut] => Array ( [0] => ANI ) [by] => RNI [Id] => 643 [key] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hy ) [norm] => true [body] => Test [cat] => Array ( [0] => drink )
[pm] => ANI|P#M#D| [pm] => Beware! [seo] => junk [pmT] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hydrogenated ) [pid] => 73 [Date] => 2011-06-02T00:00:00Z [section] => Health [sd] => 8434 [ti] => Beware [ur] => riage [kick] => [subtitle] => [image] => [Tag] => ) 

[1] => Array ( [aut] => Array ( [0] => URVASHI ASHER ) [by] => URVASHI [Id] => 345 [key] =>
Array ( [0] => film [1] => design [2] => biography [3] => bachchan [4] => cinema ) [norm] => true  [body] => division. [cat] => Array ( [0] => entertainment ) [pm] => URVASHI|P#M#D|TNN [pm] => booked [seo] => film [pmT] => Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [pid] => 72 [Date] => 2011-06-02T00:00:00Z [section] => News & Interviews [sd] => 43543543 [ti] => booked [uri] => film [kick] => [subtitle] => [image] => [Tag] => )



Please tell me how to add the 1st value from array2 and replace in array1.

The output should look like

Array ( [num_found] => 60 [articles] => 
Array ( [0] => 
Array ( [aut] => Array ( [0] => ANI ) [by] => RNI [Id] => 643 [key] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hy ) [norm] => true [body] => Test [cat] => Array ( [0] => drink )
[pm] => ANI|P#M#D| [pm] => Beware! [seo] => junk [pmT] => Array ( [0] => trans fats [1] => junk food [2] => food labels [3] => miscarriage [4] => hydrogenated ) [pid] => 73 [Date] => 2011-06-02T00:00:00Z [section] => Health [sd] => 8434 [ti] => Beware [ur] => riage [kick] => [subtitle] => [image] => [Tag] => ) 

[1] => Array ( [aut] => Array ( [0] => URVASHI ASHER ) [by] => URVASHI [Id] => 277 [key] =>
Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [norm] => true  [body] => division. [cat] => Array ( [0] => entertainment ) [pm] => URVASHI ASHER|P#M#D|TNN [pm] => booked [seo] => film [pmT] => Array ( [0] => film [1] => design [2] => biography [3] => amitabh bachchan [4] => cinema ) [pid] => 72 [Date] => 2011-06-02T00:00:00Z [section] => News & Interviews [sd] => 3921796 [ti] => Amitabh booked [uri] => film [kick] => [subtitle] => [image] => [Tag] => )

where array[0] is the value from array2.

$array1[0] = $array2[0];

Thanks.
$array1[‘articles’][0] = $array2[‘articles’][0];

Please tell me how to replace the value of “$array2[‘articles’][0];” in any of top 6 values in $array1 randomly.

“any of top 6 values in $array1 randomly”… there’s not 6 values in array1[‘articles’], so I dont know to what you’re referring.

What do you want it to do, exactly?

$array1['articles'][0] = $array2['articles'][0];

Here, $array1[‘articles’][0] is replaced with $array2[‘articles’][0].
First value is replaced. SUppose if the $array1 has many values, if array count is greater than 6, How to replace $array2[‘articles’][0], with any of the values in a $array1 randomly.

Ie. $array2[‘articles’][0], be replaced with any one of the values from
$array1[‘articles’][0] to $array1[‘articles’][6] randomly.

$temp = $array1['articles']; //Assuming you want to keep $array1 intact. If not, just use array1['articles'] whereever we have temp.
if(count($temp) > 6) {
  $temp = array_slice($temp,0,6);
  shuffle($temp);
  $array2['articles'][0] = $temp[0];
}