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
https://forums.phpfreaks.com/topic/7090-array_unique-help/
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
https://forums.phpfreaks.com/topic/7090-array_unique-help/#findComment-25796
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.