Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,902 members, 7,814,061 topics. Date: Wednesday, 01 May 2024 at 04:39 AM

Php Poop Quick Quiz :: Merging Multipart Arrays - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Php Poop Quick Quiz :: Merging Multipart Arrays (792 Views)

Most Confusing And Simple Maths Quiz / Php Oop Quick Quiz / Very Easy Html/php Quiz :) (2) (3) (4)

(1) (Reply) (Go Down)

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"wink which is same as array(0=>"Tony",1=>"Ayo"wink

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(
user1=>"Tony",
user2=>"Ayo",
user3=>"Lolade",
);

$arr2=array(
user1=>"Tade",
user2=>"Ayo",
user3=>"Lolade",
);

$arr3=array(
user1=>"Loveth",
user2=>"Akpan",
user3=>"Okon",
);


$arr4=array(
user1=>"Tade",
user2=>"Tony",
user3=>"Lolade",
);


$arr5=array(
user1=>"Tade",
user2=>"Ayo",
user3=>"Lolade",
);

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:

well well well

<?php

$final_array = $arr1 + $arr2 + $arr3 + $arr4 + $arr5

$final_array = array_values($final_array);

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 Do I Involve Ads On My Website Please / Otekbits Vs Techloy (which Nigerian Tech News Site Do You Prefer?) / Complete School Management System (both Collage And Secondary, Primary Etc) See

(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. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.