PHP - Duplicates In Complex Array
Hi I have an array from an sql query and i would like to eliminates all the duplicates, i have google search for an answer without success, any help would be aprecciated $result = $stmt->fetchAll(PDO::FETCH_ASSOC); $final = array(); $json = array(); if ($idCoord > 0 || $isDirecao > 0) { foreach ($result as $row) { $idAtividade = $row['idAtividade']; if (!isset($final[$idAtividade])) { $final[$idAtividade]['Escola'] = $row['Escola']; $final[$idAtividade]['Atividade'] = $row['Atividade']; $final[$idAtividade]['Periodo'] = $row['Periodo']; $final[$idAtividade]['Mes'] = $row['Mes']; $final[$idAtividade]['haveClasses'] = $row['haveClasses']; $final[$idAtividade]['DataPrevista'] = $row['DataPrevista']; $final[$idAtividade]['Destinatarios'] = $row['Destinatarios']; $final[$idAtividade]['Orcamento'] = $row['Orcamento']; $final[$idAtividade]['Organizador'] = $row['Organizador']; $final[$idAtividade]['Obs'] = $row['Obs']; $final[$idAtividade]['PdfAtividade'] = $row['PdfAtividade']; $final[$idAtividade]['Avaliacao'] = $row['Avaliacao']; $final[$idAtividade]['idProfessor'] = $row['idProfessor']; $final[$idAtividade]['PdfAvaliacao'] = $row['PdfAvaliacao']; $final[$idAtividade]['Validado'] = $row['Validado']; $final[$idAtividade]['Nome'] = array(); $final[$idAtividade]['Grupo'] = array(); $final[$idAtividade]['Departamento'] = array(); } $final[$idAtividade]['Nome'][] = $row['Nome']; $final[$idAtividade]['Grupo'][] = $row['Grupo']; $final[$idAtividade]['Departamento'][] = $row['Departamento']; } foreach ($final as $idVisita => $reservation) { $json[] = $reservation; } } echo json_encode($json); } And this is an example i'm receiving
So you can see that Grupo has 4 times the value "500" and Departamento has 4 times that string... How can avoid this and have only one value of each?
Thanks
Similar TutorialsQuote Hi guys im trying to get rid of records with duplicate phone numbers here's my array Code: [Select] Array ( [0] => Array ( [0] => 11-1-89677-362123164 [1] => 11 [2] => testadmin [3] => 61415676836 [4] => 2011-11-16 [5] => 1 [6] => 0 [7] => 0 [8] => [9] => 0 [10] => 0 [11] => 0 ) [1] => Array ( [0] => 11-1-89688-362186603 [1] => 11 [2] => testadmin [3] => 61415556677 [4] => 2011-08-12 [5] => 0 [6] => 0 [7] => 0 [8] => [9] => 0 [10] => 0 [11] => 0 ) [2] => Array ( [0] => 11-1-89689-362186773 [1] => 11 [2] => testadmin [3] => 61415676836 [4] => 2011-08-12 [5] => 0 [6] => 0 [7] => 0 [8] => [9] => 0 [10] => 0 [11] => 0 ) [3] => Array ( [0] => 11-1-89690-362186926 [1] => 11 [2] => testadmin [3] => 61415223344 [4] => 2011-08-12 [5] => 0 [6] => 0 [7] => 0 [8] => [9] => 0 [10] => 0 [11] => 0 ) ) Quote I can't quit figure this out any sujestions would be gold,,, this is my attempt but its not working Code: [Select] $final = array(); foreach ($phoneNumberArray as $array[3]) { if(!in_array($array, $final)){ $final[] = $array; } } print_r($final); So Im building this little link scraper. The problem I am having is when it outputs the links that are in the array its got duplicate elements. I'm trying to erase the dupes and only show unique values. I've tryed array_unique() with out success as well as in_array(). Any help would be appreciated! //PAGE WE ARE GETTING LINKS ON $diags = str_get_html(getDiagramLinks($html)); //GET THE DIAGRAM LINKS TO PAGES INTO ARRAY foreach($diags->find('a') as $f) { $diagLinks[] = $f->href; } //iterate through the array for($i=0; $i<sizeof($diagLinks); $i++) { //ignore if blank element if(trim($diagLinks[$i]) !== ' ') { echo $diagLinks[$i]. '<br>'; } } The Output: Code: [Select] /partsearch/model.aspx?diagram_id=110375 /partsearch/model.aspx?diagram_id=110375 /partsearch/model.aspx?diagram_id=110376 /partsearch/model.aspx?diagram_id=110376 /partsearch/model.aspx?diagram_id=110377 /partsearch/model.aspx?diagram_id=110377 /partsearch/model.aspx?diagram_id=110378 /partsearch/model.aspx?diagram_id=110378 /partsearch/model.aspx?diagram_id=110379 /partsearch/model.aspx?diagram_id=110379 /partsearch/model.aspx?diagram_id=110380 /partsearch/model.aspx?diagram_id=110380 Hi, got a problem with my arrays, every string gets duplicated 11 times instead of just one time. How to fix this? Hi guys! i got this code: Code: [Select] <? $x = "abcde"; str_split($x); for ($k=0; $k<=119; $k++){ $ax = array($x[0],$x[1],$x[2],$x[3],$x[4]); shuffle($ax); $text = implode("", $ax) . ""; echo $text; echo "<br />"; } ?> if you test it you see that it is working but giving me allot of duplicates results! there is a way to ignore duplicaes while it is runing? thanx. Hi All, I've a loop which creates an array as follows: $product_table[] = ['SKU' => $sku, 'Label' => $attribute_name, 'Value' => $term_obj->name ]; I'm then grouping the data by SKU code: #group the products by SKU $group_products = array(); foreach ($product_table as $element) : $group_products[$element['SKU']][] = $element; endforeach; Finally, I output the data: #output the data foreach ($group_products as $itemName => $rows) : echo '<tr>'; #echo '<td>', $element['SKU'], '</td>'; $i=0; foreach ($rows as $row) : $i++; #echo '<td>'. $row["SKU"]. '</td><td>'. $row["Label"]. '</td><td>'. $row["Value"]. '</td>'; if ($i == 1): echo '<td>'. $row["SKU"]. '</td><td>'. $row["Value"]. '</td>'; else: echo '<td>'. $row["Value"]. '</td>'; endif; #echo '<td>'. $row["Value"]. '</td>'; endforeach; echo '</tr>'; endforeach; ?> And looks like: Product code System Pack Quantity XT1CWH System 1 1 x 3m XT2CWH System 2 1 x 3m XT3CWH System 3 1 x 3m
This works perfectly fine. However, some products share the same SKU and therefore it causes an issue, like the below: Product code System Pack Quantity XT1CLWH System 1 8 x 3m System 2 8 x 3m System 3 8 x 3m Is there a way I can avoid this, so if perhaps creates the new row but shows the same SKU code? Many thanks I wish to get only the last part of each array 'g' And then show non duplicated 'g' but in the same order that it was in the original array. Code: [Select] <?php $formarray = array( 'name' => array( 'i1'=> array('a'=>'a1', 'b'=>'b1', 'c'=>'c1', 'd'=>'d1', 'e'=>'e1', 'f'=>'f1', 'g'=>'g1'), 'i2'=> array('a'=>'a2', 'b'=>'b2', 'c'=>'c2', 'd'=>'d2', 'e'=>'e2', 'f'=>'f2', 'g'=>'g2'), 'i3'=> array('a'=>'a3', 'b'=>'b3', 'c'=>'c3', 'd'=>'d3', 'e'=>'e3', 'f'=>'f3', 'g'=>'g3'), 'i4'=> array('a'=>'a4', 'b'=>'b4', 'c'=>'c4', 'd'=>'d4', 'e'=>'e4', 'f'=>'f4', 'g'=>'g4'), ) ); foreach ($formarray as $newarray => $a) { ?><strong><?=$newarray;?></strong><br><? foreach ($a as $key => $k) { ?>"<?=$key;?>", <? foreach ($k as $b) { //if ($k['DBfield'] != "") { ?>"<?=$b;?>", <? //} } ?><br><? } //end of second foreach ?><br><br><br><? } //end of first foreach ?> Doing an API call and want to remove duplicates so I can display the products by brand. Problem I am having now is when I try to display the brands, I am getting duplicate brands. When I display the brands I am getting Nike, Nike, Reebook. When I just want, Nike, Reebok. My Code Code: [Select] <?php $results = array(); //array from API call $results2 = $results['data']; function multi_unique($array) { foreach ($array as $k=>$na) $new[$k] = serialize($na); $uniq = array_unique($new); foreach($uniq as $k=>$ser) $new1[$k] = unserialize($ser); return ($new1); } $results3 = multi_unique($results2); foreach ($results3 as $var) { echo $var['brand']; ?> <br /> <?php } ?> The array Code: [Select] { "errors": [ ], "warnings": [ ], "data": [ { "url": "http://[...]", "image_url": "[...]", "image_thumb_url": "[...]", "keyword": "Red Running Shoes", "description": "Red Running Shoes - Perfect for long jogs!", "category": "Shoes", "price": "59.99", "price_sale": null, "currency": "USD", "merchant": "", "brand": "Nike", "upc": "0944588778", "isbn": null, "sales": 23 }, { "url": "http://[...]", "image_url": "http://[...]", "image_thumb_url": null, "keyword": "Blue Running Shoes", "description": "Blue Running Shoes - Perfect for long jogs!", "category": "Shoes", "price": "59.99", "price_sale": "49.99", "currency": "USD", "merchant": "", "brand": "Nike", "upc": "0944588779", "isbn": null, "sales": 12 } { "url": "http://[...]", "image_url": "http://[...]", "image_thumb_url": null, "keyword": "Black Running Shoes", "description": "Black Running Shoes - Perfect for long jogs!", "category": "Shoes", "price": "59.99", "price_sale": "49.99", "currency": "USD", "merchant": "", "brand": "Reebok", "upc": "0944554779", "isbn": null, "sales": 12 } ], "coupons": [ ], "countryCode": "US", "page": 1, "limit": 10, "totalRecords": 3 } Hello I have a while loop which outputs countrys from the database (im making a "filter by" function). For example, the loop outputs: Denmark Belgium Holland Brazil Japan Brazil Denmark I want to sort these alphabetically and then remove duplicates... Can somebody explain to me how? I don't know how to get them into an array to do it... Hi, I have got some data out of my database, I would now like to sort all of this by putting the data into arrays, something looking like this: branch - costs - profit France - 406.85 - 1392.48 So each branch is one item in the array, but has the costs and profit with it too. I would then like to sort those arrays by things like branch name, costs and profit. Is this possible? Phew, okay, I'm at my wits end on how to accomplish this task. My client wants a forum program, but she wants it different from normal in that the forum page won't show just the main threads where you would have to click to see the replies, etc - she wants the forum page to display threads and replies in a tiered fashion. Something like this: Code: [Select] - Thread 1 - Reply 1-1 - Reply 1-1-1 - Reply 1-2 - Reply 1-3 - Reply 1-3-1 - Reply 1-3-1-1 - Reply 1-3-1-1-1 - Reply 1-3-1-2 - Reply 1-3-2 - Thread 2 - Thread 3 - Reply 3-1 etc So, the threads should be arranged in order of their property timeLastChanged (which is updated on replies to it, replies to replies of it, edits, etc) which produces the "bumping" functionality. Then the replies under it should be arranged in order of their property timeStarted (which is the timestamp of when it got created). Now, I have the script so far to the point where I have 3 arrays of objects (stickyObjs, mainsObjs, replyObjs) and these objects are instances of Post with their properties being their database values (author, timeStarted, subject, etc). Now, I have thought to arrange these arrays into one big array of objects in the order that they should appear on the page (don't worry about the indent, that's done elsewhere.) Anyway, how would I go about sorting these arrays into one big array of objects in the order they should appear with those two sorting criteria above (sorting criteria is stickies, 1st main in the order of last available timeLastChanged, any replies to mains, replies to replies, ad nauseum in order of timeStarted, then the next main in the order of timeLastChanged, etc.) I have gone through many possible ways, all of which are incredibly complex and involve many copies of arrays and pointers to objects in arrays and iteration counters and GAH! Does anyone know of an easy way to accomplish this sorting? Here is what I have so far: Code: [Select] class Category { public $title; public $majCatID; public $catID; public $modLevel; public $postingLevel; public $hostedByUID; public $order; public $shortName; public $info; public $stickyObjs; public $mainsObjs; public $replyObjs; private $database; public function __construct($catID) { $this->database = new TBDatabase; $result = $this->database->getIntRow(CAT_TABLE, 'catID', $catID); $row = $this->database->fetchAssoc($result); $this->title = $row['title']; $this->majCatID = $row['majCatID']; $this->catID = $row['catID']; $this->modLevel = $row['modLevel']; $this->postingLevel = $row['postingLevel']; $this->hostedByUID = $row['hostedByUID']; $this->order = $row['order']; $this->shortName = $row['shortName']; $this->info = $row['info']; $this->pointer = 0; } public function sortPosts() { $table = $this->shortName."_threads"; $this->getStickyObjs(); $numStickies = count($this->stickyObjs); $this->getMainObjs(); $numMains = count($this->mainsObjs); $this->getReplyObjs(); $numReplies = count($this->replyObjs); } private function getStickyObjs() { $result = $this->database->getPostResources($this->shortName, $this->catID, "AND isSticky = 1"); if (!$result) { $this->stickyObjs = false; return; } $i = 1; while ($row = $this->database->fetchAssoc($result)) { $this->stickyObjs[$i] = new Post($row); $i++; } return; } private function getMainObjs() { $result = $this->database->getPostResources($this->shortName, $this->catID, "AND isReply = 0"); if (!$result) { $this->mainsObjs = false; return; } $i = 1; while ($row = $this->database->fetchAssoc($result)) { $this->mainsObjs[$i] = new Post($row); $i++; } return; } private function getReplyObjs() { $result = $this->database->getPostResources($this->shortName, $this->catID, "AND isReply != 0"); if (!$result) { $this->replyObjs = false; return; } $i = 1; while ($row = $this->database->fetchAssoc($result)) { $this->replyObjs[$i] = new Post($row); $i++; } return; } } Thanks! I've been stuck on this for about a week so I was wondering if I can get some help from you guys! Basically I'm exporting an array of values to a CSV file, within that array are two other arrays containing data I need. What I need to work out is how I can create a CSV with headers for these values, then with the nested arrays also print their values into the same rows as the first array. Example: $List = array ( 'Product ID' => '10', 'Customer Address' => '123 Fake Street', array( array('Product Name'=>'Product1', 'Product Price'=>'10.00', 'Product Reference'=>'HGJEN'), array('Product Name'=>'Product2', 'Product Price'=>'5.00', 'Product Reference'=>'HGJTN'), array('Product Name'=>'Product3', 'Product Price'=>'10.00', 'Product Reference'=>'HGJNN'), ), array( array('Product Customisation Name'=>'Additional Info', 'Customisation Value'=>'Things are great.'), array('Product Customisation Name'=>'Image Upload', 'Customisation Value'=>'Logo.jpg'), ), 'Telephone Number'=>'999', ); To be exported to something looking like this: Product ID Customer Address Product Name Product Price Product Reference Product Cus Name Cus Value Telephone Number 10 123 Fake Street Product2 5.00 HGJTN Additional Info Things are great 999 10 123 Fake Street Product1 10.00 HGJEN Image Upload Logo.jpg 999 10 123 Fake Street Product3 10.00 HGJNN 999 If anyone could help me out in anyway I would be so appreciative, I'm sure this ones going to end up killing me! Hi guys, I'm using the API for Remember the Milk through a PHP class that I found online called PHP-RTM. Anyway after so much headaches (the authentication for the Remember the Milk API is one of the hardest I've ever come across) I've finally connected everything and gotten to the stage that I have some raw data inside an array. The next step is to work with that data. Basically I want to access the names of the task in a complex multi demensional array and I have no idea how to do this. I have done a var_dump of the array I am working with to show you the complexity. Just remember that in the complex var_dump below there are only 4 tasks: array(2) { ["stat"]=> string(2) "ok" ["tasks"]=> array(2) { ["rev"]=> string(31) "nxeir6vy9pcgcggoss4wwwooc8cwo8w" ["list"]=> array(3) { [/tt][list][li][tt]=> array(2) { ["id"]=> string( 8) "13927305" ["taskseries"]=> array(2) { [/tt][/li][li][tt]=> array(11) { ["id"]=> string(9) "104056511" ["created"]=> string(20) "2011-02-02T12:48:48Z" ["modified"]=> string(20) "2011-02-02T12:48:48Z" ["name"]=> string(42) "Send confirmation email to luxury car hire" ["source"]=> string(13) "iphone-native" ["url"]=> string(0) "" ["location_id"]=> string(0) "" ["tags"]=> array(0) { } ["participants"]=> array(0) { } ["notes"]=> array(0) { } ["task"]=> array(9) { ["id"]=> string(9) "156815180" ["due"]=> string(20) "2011-02-02T13:00:00Z" ["has_due_time"]=> string(1) "0" ["added"]=> string(20) "2011-02-02T12:48:48Z" ["completed"]=> string(0) "" ["deleted"]=> string(0) "" ["priority"]=> string(1) "N" ["postponed"]=> string(1) "0" ["estimate"]=> string(0) "" } } [1]=> array(11) { ["id"]=> string(9) "104148150" ["created"]=> string(20) "2011-02-03T01:25:57Z" ["modified"]=> string(20) "2011-02-03T01:26:17Z" ["name"]=> string(40) "Confirm that post has been sent with DVD" ["source"]=> string(2) "js" ["url"]=> string(0) "" ["location_id"]=> string(0) "" ["tags"]=> array(0) { } ["participants"]=> array(0) { } ["notes"]=> array(0) { } ["task"]=> array(9) { ["id"]=> string(9) "156951316" ["due"]=> string(20) "2011-02-02T13:00:00Z" ["has_due_time"]=> string(1) "0" ["added"]=> string(20) "2011-02-03T01:25:57Z" ["completed"]=> string(0) "" ["deleted"]=> string(0) "" ["priority"]=> string(1) "N" ["postponed"]=> string(1) "0" ["estimate"]=> string(0) "" } } } } [1]=> array(2) { ["id"]=> string( 8) "13925842" ["taskseries"]=> array(12) { ["id"]=> string( 8) "98105089" ["created"]=> string(20) "2010-12-19T11:25:25Z" ["modified"]=> string(20) "2011-02-02T13:01:42Z" ["name"]=> string(25) "Read for one hour per day" ["source"]=> string(13) "iphone-native" ["url"]=> string(0) "" ["location_id"]=> string(0) "" ["rrule"]=> array(2) { ["every"]=> string(1) "1" ["$t"]=> string(21) "INTERVAL=1;FREQ=DAILY" } ["tags"]=> array(0) { } ["participants"]=> array(0) { } ["notes"]=> array(0) { } ["task"]=> array(9) { ["id"]=> string(9) "156576423" ["due"]=> string(20) "2011-02-02T13:00:00Z" ["has_due_time"]=> string(1) "0" ["added"]=> string(20) "2011-02-01T13:01:45Z" ["completed"]=> string(0) "" ["deleted"]=> string(0) "" ["priority"]=> string(1) "N" ["postponed"]=> string(1) "0" ["estimate"]=> string(0) "" } } } [2]=> array(2) { ["id"]=> string( 8) "17007566" ["taskseries"]=> array(11) { ["id"]=> string(9) "104017503" ["created"]=> string(20) "2011-02-02T05:45:04Z" ["modified"]=> string(20) "2011-02-03T02:29:55Z" ["name"]=> string(96) "Hook up watermark for both videos (check email) and send to Rachelle and Steve at compare quotes" ["source"]=> string(2) "js" ["url"]=> string(0) "" ["location_id"]=> string(0) "" ["tags"]=> array(0) { } ["participants"]=> array(1) { ["contact"]=> array(3) { ["id"]=> string(7) "2150286" ["fullname"]=> string(10) "Samuel Nam" ["username"]=> string(10) "samuel.nam" } } ["notes"]=> array(0) { } ["task"]=> array(9) { ["id"]=> string(9) "156754354" ["due"]=> string(20) "2011-02-02T13:00:00Z" ["has_due_time"]=> string(1) "0" ["added"]=> string(20) "2011-02-02T05:45:04Z" ["completed"]=> string(20) "2011-02-03T02:32:00Z" ["deleted"]=> string(0) "" ["priority"]=> string(1) "N" ["postponed"]=> string(1) "0" ["estimate"]=> string(0) "" } } } } } } Anyone know the code i can use to simply get the "name" keys from the complex array below. I've created a movie to show what I'm trying to achieve, please click below to view: http://screenr.com/XIY MOD EDIT: formatted text to get rid of errant smilies . . . [/list] I'm figuring out a code that runs through several checkboxes, then checks the mysql table to enter any checked boxes if they don't already exist, and to delete any entries that might exist matching the unchecked boxes. This is as far as I've gotten. I had it working, but it chokes on the table key. I want to skip over existing entries... Code: [Select] if (isset($_POST['submit'])){ require ('db.php'); $id1 = $_POST['plant_id']; $imploder=implode(',', $_POST['option2']); $exploder = explode(',', $imploder); foreach($exploder as $value) { $add = "INSERT INTO table(plant_id, edible_id) VALUES ($id1, $value) WHERE plant_id = $id AND edible_id != $value"; $delete = "DELETE FROM table WHERE plant_id = $id1 and edible_id NOT IN $exploder"; }; $result2 = mysql_query($add) or die(mysql_error()); if (mysql_affected_rows() > 0) { echo '<div style="position:relative; left:16px; top:216px;"><font color="red">updated!</font></div>'; } } ?> I've made a small chicken names website, and I also have a chicken name list as a thread on a chicken related forum. People submit their names, and I manually add them to the list. With the names growing so much, I decided to make a small background system that lets me put in the current list names, then the new names submitted. It will then run the lists, compare them, and spit out/ignore any duplicates and generate the new list. But each time I use it, it doesn't get rid of the duplicates. Can anyone tell me why? if($_GET['list_updater'] || $_POST['list_updater']) { if(!$_POST['current_list'] || !$_POST['new_names']) { ?> <table> <form action="index.php" method="POST"> <input type="hidden" name="list_updater" value="1"> <tr> <td> <textarea name="current_list" cols="40" rows="20"></textarea> </td> </tr> <tr> <td> <textarea name="new_names" cols="40" rows="20"></textarea> </td> </tr> <tr> <td><input type="submit" value="Generate New List"></td> </tr> </form> </table> <?php } else { //start our counting numbers $x = 0; $s = 0; $a = 0; //make our arrays $check_to[0]; $new[0]; //get the values from our lists $old_list = explode("\n",$_POST['current_list']); $new_list = explode("\n",$_POST['new_names']); //get new list variables foreach($old_list as $value) { $check_to[$x] = $value; $x++; } //add all our new names foreach($new_list as $value) { for($s = 0; $s < count($new_list); $s++) { } } ?> <textarea cols="45" rows="20"> <?php for($t = 0; $t < count($new); $t++) { echo $new[$t]; } ?> </textarea> <?php } } Hi, I have a database table which is full of books e.g book_title, book_author, book_date etc. Im trying to work out a way to list all the authors without duplicating them, if that makes sense. If I do a simple query and then display the book_author in a loop it will show multiple entries for each author. I just want it to display each author once. Hope that makes sense lol sorry Im a newbie. Anyone know how I can do it ? Thanks in advance, Scott. I have a switch, which i use to alternate between two numbers. But for some reason, a duplicate occurs exactly at the count of 4, and i haven't been able to figure out why. Code: [Select] $Count = 1; switch ($Count) { case 1: ++$Count; break; case 2: --$Count; break; } Should output: Code: [Select] 2 1 2 1 2 ...But for some reason it gives the below instead.. Code: [Select] 2 1 2 1 1 2 1 ... Subsequent output after the error appears completely normal. I need a way to keep entrys into a database from being doubled. The issue is that on something like %7B%7D that is the same as {} in html. So if one is entered in with the percentages and one is entered in normal, the data base thinks they are two different items even though they could be the exact same thing. Now when I insert the new item into the data base the value ='s mysql_real_escape_string(htmlentities(item)) is how I do it now. This is wrong im guessing cause it could go with either of the above examples and puts them in as given. So my question here is kinda two parted. 1) how do I get it to insert the info one way or the other but never both being allowed. So {} will always show %7B%7D when inserted or visa versa. and 2) How do I take an existing database and sort threw it to make sure they are all the same as 1 codes the new ones in, and take out any possible dupilications due to the difference? Hello im trying to write a simple script so that before my website inserts an account into the database it checks to see if that email already exists. Heres what i got but it does not work. //script for checking if the email account already exists $CheckEmail = "SELECT * FROM Members WHERE email='".$email."'"; $EmailQuery = mysql_query($CheckEmail); $Emailresult = mysql_fetch_array($EmailQuery); $GotEmail = mysql_num_rows($EmailResult); if($GotEmail != 0) { $emailDup= "This email account has already been registered"; } else { //run the rest of my scripts later down the page I have this to echo the message <? if($GotEmail)==1 echo $emailDup; ?> I have a table that has pairs of matching records that are identified as matching on a specific column. In other words, 2 users submit data on the same record, and they are identified as matching and belonging to the same record data because the table column gameid is the same for the pair. How can I output the information for the pair of matching records for each of these into a table repeating it until Ive looped through all records? In other words I want to create 1 table with headers for each matching pair all the way down... thanks in advance. I've been working on this too long, without having it figured out. Starting to get a bit 'kooky' at this point! I'm one stage away from retarded frustration. I have two arrays, such as these: Array 1 ( => 7|1|0|5|0|0 [1] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 ) Array 2 ( => 8|1|0|5|0|0 [1] => 7|2|0|5|0|0 [2] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 ) I am trying to write a piece of code that will compare every value in array 2 to every value in array 1 and if the first 2 NUMERICAL values do not exist in Array 1, they are to be added to it. So, in the end, after comparison, Array 1 should look like this: Array 1 ( => 7|1|0|5|0|0 [1] => 7|3|0|5|0|0 [3] => 7|4|0|5|0|0 [4] => 7|5|0|5|0|0 [5] => 7|6|0|5|0|0 [6] => 7|7|0|5|0|0 => [7] => 8|1|0|5|0|0 [8] => 7|2|0|5|0|0) The values 7|3|0|5|0|0 and 7|4|0|5|0|0 from Array 2 have not been added to Array 1 because 7|3... and 7|4... already exist in Array 1. So far, I've got something like this: Code: [Select] $match = 0; foreach ($array1 as $data1) { foreach ($array2 as $data2) { if ($data1 == $data2) { $match = 1; break; } } if ($match != 1) { array_push($array1, $data2); } else {$match = 0;} } Where have I gone wrong? |