easyedy Posted January 3, 2008 Share Posted January 3, 2008 foreach (array($item[$FA][$SA]) as $item) { echo $item['Name']; } It just returns the first 'Name' of the array.... Here is what the array looks like.: Array ( [$FA] => Array ( [$SA] => Array ( [0] => Array ( [iD] => 390517 [Name] => Bill [1] => Array ( [iD] => 390519 [Name] => Mike [3] => Array ( [iD] => 390533 [Name] => Sam ) ) ) Quote Link to comment https://forums.phpfreaks.com/topic/84376-remove-duplicates-froma-multidimensional-array/ Share on other sites More sharing options...
sKunKbad Posted January 3, 2008 Share Posted January 3, 2008 How about creating a static array in the foreach loop and add each $item to the array. Then use an if statement to delete each $item if it is already in the array. Quote Link to comment https://forums.phpfreaks.com/topic/84376-remove-duplicates-froma-multidimensional-array/#findComment-429759 Share on other sites More sharing options...
Daukan Posted January 3, 2008 Share Posted January 3, 2008 Do you want remove duplicate names, ids, or duplicate arrays in the array? Quote Link to comment https://forums.phpfreaks.com/topic/84376-remove-duplicates-froma-multidimensional-array/#findComment-429765 Share on other sites More sharing options...
easyedy Posted January 3, 2008 Author Share Posted January 3, 2008 Remove duplicate id's & names. Quote Link to comment https://forums.phpfreaks.com/topic/84376-remove-duplicates-froma-multidimensional-array/#findComment-429770 Share on other sites More sharing options...
Barand Posted January 3, 2008 Share Posted January 3, 2008 try <?php $items = array ( 'x' => array ( 'y' => array ( 0 => array ( 'ID' => 390517, 'Name' => 'Bill' ), 1 => array ( 'ID' => 390519, 'Name' => 'Mike' ), 2 => array ( 'ID' => 390533, 'Name' => 'Sam' ), 3 => array ( 'ID' => 390519, 'Name' => 'Mike' ) ) ) ); /** * remove dupes */ $a = $items['x']['y']; $k = count($a); for($i=0; $i < $k-1; $i++) { for($j=$i+1; $j < $k; $j++) { if ($a[$i] == $a[$j]) unset($a[$j]); } } $items['x']['y'] = $a; echo '<pre>', print_r($items, true), '</pre>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84376-remove-duplicates-froma-multidimensional-array/#findComment-429796 Share on other sites More sharing options...
easyedy Posted January 10, 2008 Author Share Posted January 10, 2008 This works but for one fact... sometimes the names are the same but the ID is diff... Ie : Mike can have an ID of 390517, another Mike cna have an ID of 390557... We just want it so there is only 1 name of each. Quote Link to comment https://forums.phpfreaks.com/topic/84376-remove-duplicates-froma-multidimensional-array/#findComment-435637 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.