sandy1028 Posted June 2, 2011 Share Posted June 2, 2011 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 2, 2011 Share Posted June 2, 2011 $array1[0] = $array2[0]; Quote Link to comment Share on other sites More sharing options...
sandy1028 Posted June 2, 2011 Author Share Posted June 2, 2011 Thank you. BUt this solution doesn't work Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 2, 2011 Share Posted June 2, 2011 Thank you. BUt this solution doesn't work where array[0] is the value from array2. Because you didn't specify the above correctly. The "method" I provided will work. YOU should have been able to modify it for your particular needs. Looking at the structure a little closer I think this is what you need. If not, YOU need to take some responsibility to understand the structure and modify it accordingly. $array1['articles'][0] = $array2['articles'][0]; Quote Link to comment Share on other sites More sharing options...
sandy1028 Posted June 3, 2011 Author Share Posted June 3, 2011 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. Quote Link to comment Share on other sites More sharing options...
sandy1028 Posted June 3, 2011 Author Share Posted June 3, 2011 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 3, 2011 Share Posted June 3, 2011 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. What do you mean by "in any of top 6 values in $array1"? Do you mean: $array1['articles'][0], $array1['articles'][1] . . . $array1['articles'][5]? If so, then //Create a random index 0-5 (or max of those avail in array1) $randIdx = rand(0, max(count($array1['articles']), 5)); $array1['articles'][$randIdx] = $array2['articles'][0]; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.