Jump to content

array_unique help


tuna

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.