If I have an array DGN, DGN, TEST, TEST3,TEST3, TEST4, TEST4 and this is being transferred to a text box. How can I remove the duplicate entries? Example code: //While the URL is passing the cc string // DGN, DGN, TEST, TEST3,TEST3, TEST4, TEST4 $cc = $_GET['cc']; PHP: <input name="ccc" type="text" value="<?php echo "$cc";?>"/> HTML: Any and all help with this would be greatly appreciated. I been racking my head around and think I have been over thinking this for to long that I cant figure it out. TJ
use the array_unique($array) function which is built into php. It removes all duplicate values from an array. $cc = array_unique($cc); PHP:
tried it. //While the URL is passing the cc string // DGN, DGN, TEST, TEST3,TEST3, TEST4, TEST4 $cc = "DGN, DGN, TEST, TEST3,TEST3, TEST4, TEST4"; print_r($cc); echo "<BR>"; $cc = trim($cc); print_r($cc); echo "<BR>"; $c = explode(" , ", $cc); print_r($cc); echo "<BR>"; $cc = array_unique($cc); print_r($cc); PHP: doesnt work.
It does work. The real issue here is that you are not using descriptive variable names which makes debugging code a nightmare. Try this: <pre><?php $myString = "DGN,DGN,TEST,TEST3,TEST3,TEST4,TEST4"; print_r($myString); echo "<BR>"; $myString = trim($myString); print_r($myString); echo "<BR>"; $myArray = explode(",", $myString); print_r($myArray); echo "<BR>"; $myArray = array_unique($myArray); print_r($myArray); ?></pre> PHP: Brew
thank you. Now while it shows Array ( [0] => DGN [1] => DGN [2] => TEST [3] => TEST3 [4] => TEST3 [5] => TEST4 [6] => TEST4 ) Array ( [0] => DGN [2] => TEST [3] => TEST3 [5] => TEST4 ) Code (markup): How can I get the second set to display together as DGN, TEST, TEST3, TEST4 shown as $cc = DGN, TEST, TEST3, TEST4; to be able to display it in the form text area? And again I do appreciate all the help guys and gals. TJ