tuna Posted April 11, 2006 Share Posted April 11, 2006 if i have an array like this[code]array(6) { [5]=> array(1) { [0]=> string(8) "20060411" } [4]=> array(1) { [0]=> string(8) "20060407" } [3]=> array(1) { [0]=> string(8) "20060411" } [2]=> array(1) { [0]=> string(8) "20060411" } [1]=> array(1) { [0]=> string(8) "20060407" } [0]=> array(1) { [0]=> string(8) "20060407" }}[/code]How would i remove the duplicates using the array_unique function ?i've tried many ways, and still cant seem to get it thanks Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted April 11, 2006 Share Posted April 11, 2006 array(1)=array_unique(array(1)); doesn't work? Quote Link to comment Share on other sites More sharing options...
tuna Posted April 11, 2006 Author Share Posted April 11, 2006 the array(x) is the count (how many items in that array) Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 11, 2006 Share Posted April 11, 2006 Try[code]<?php$curr_array = array ( 5=> array ( 0=>"20060411" ), 4=> array ( 0=>"20060407" ), 3=> array( 0=>"20060411" ), 2=> array( 0=>"20060411" ), 1=> array( 0=>"20060407" ), 0=> array( 0=>"20060407" ));echo '<pre>' . var_export($curr_array,true) . '</pre>';$new_array = array();foreach($curr_array as $k => $v) $new_array[$k] = serialize($curr_array[$k]);$curr_array = array();foreach(array_unique($new_array) as $k => $v) $curr_array[$k] = unserialize($new_array[$k]);echo '<pre>' . var_export($curr_array,true) . '</pre>';?>[/code]This has been tested and works.Ken Quote Link to comment 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.