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 Link to comment https://forums.phpfreaks.com/topic/7090-array_unique-help/ 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? Link to comment https://forums.phpfreaks.com/topic/7090-array_unique-help/#findComment-25783 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) Link to comment https://forums.phpfreaks.com/topic/7090-array_unique-help/#findComment-25795 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 Link to comment https://forums.phpfreaks.com/topic/7090-array_unique-help/#findComment-25796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.