Stats: 3,190,127 members, 7,939,541 topics. Date: Wednesday, 04 September 2024 at 07:58 AM |
Nairaland Forum / Science/Technology / Webmasters / Php Poop Quick Quiz :: Merging Multipart Arrays (808 Views)
Most Confusing And Simple Maths Quiz / Php Oop Quick Quiz / Very Easy Html/php Quiz :) (2) (3) (4)
Php Poop Quick Quiz :: Merging Multipart Arrays by Nobody: 9:09pm On Jul 20, 2011 |
In this scenario, dual core who was very busy validating websites on http://www.trudigits.com/ was at the same time pinging some babes, so he got infos mixed up. If you noticed, dual ehm created up to 5 different arrays, and the arrays are keyed for that matter. But as usual he mixed up and mentioned some names more than once. And really, no name should be repeated. Now, this is just a small fragment of the information. Immagine each of those arrays running into millions of data - so you cannot manually fix the errors. You are now required to formulate an array of just number and value. I mean an array like this array("Tony","Ayo" ![]() ![]() This means that you are to merge all the 5 arrays into one single array, and you must also make sure that no name is repeated at all. $arr1=array( Let me give a little assistance: You may optionally first merge the arrays into a single multidimensional one like this and. . .you know $arr[]=$arr1; $arr[]=$arr2; $arr[]=$arr3; $arr[]=$arr4; $arr[]=$arr5; Beware: array_merge is a php function that can merge 2 arrays together, but it will not help you in this case (for reasons - sorry - out of scope) However, array_unique might come in handy. . . And please note, it is not compulsory that you sort the final array Whoever writes the shortest code to solve this problem is the winner. |
Re: Php Poop Quick Quiz :: Merging Multipart Arrays by sayhi2ay(m): 10:25pm On Jul 21, 2011 |
shouldnt your array keys be quoted? array_unique(array_merge(array_values($arr1), array_values($arr2), array_values($arr3), array_values($arr4), array_values($arr5))); |
Re: Php Poop Quick Quiz :: Merging Multipart Arrays by Nobody: 10:37pm On Jul 21, 2011 |
Aho, that is fantastica. The quizzy part of it is how you make use of the array_merge and the array_values. An ordinary array_merge will not have solved the problem. Any other contestant per chance? |
Re: Php Poop Quick Quiz :: Merging Multipart Arrays by binkabir(m): 11:30pm On Jul 21, 2011 |
well well well <?php $final_array = $arr1 + $arr2 + $arr3 + $arr4 + $arr5 $final_array = array_values($final_array); ?> |
Re: Php Poop Quick Quiz :: Merging Multipart Arrays by binkabir(m): 11:32pm On Jul 21, 2011 |
well well well <?php $final_array = $arr1 + $arr2 + $arr3 + $arr4 + $arr5 $final_array = array_values($final_array); |
Re: Php Poop Quick Quiz :: Merging Multipart Arrays by Nobody: 11:39pm On Jul 21, 2011 |
binkabir: The output is incorect amigo. Did you test it properly? |
Re: Php Poop Quick Quiz :: Merging Multipart Arrays by Mobinga: 10:11am On Jul 22, 2011 |
@dhtml nairalands ssh |
Re: Php Poop Quick Quiz :: Merging Multipart Arrays by Nobody: 1:22pm On Jul 22, 2011 |
Na wa o |
(1) (Reply)
How To Stay Ahead Of Competition In Your Business / Can I Learn Web Design And Development As A Self-tutor / JQUERY - The Future Of Web Design
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11 |