1

I have a multi dimension array and it was working fine with PHP 5.2 and now it is not working with php 5.5.9. I debugged and find out that array_unique is not working . This is my code

array_push($import, $importtime, $regions); 
    array_push($imports, $import);
$imports = array_unique($imports);

foreach ($imports as $imp)
{


}

When I print_r impots before array unique, it is showing correct data but when I do print_r after array unique, it is not showing the data. Any idea?

Bharat Paudyal
  • 124
  • 1
  • 10

1 Answers1

1

http://php.net/manual/de/function.array-unique.php

PHP 5.2 did sort differently then current versions.

sort_flags The optional second parameter sort_flags may be used to modify the sorting behavior using these values:

Sorting type flags:

  • SORT_REGULAR - compare items normally (don't change types)
  • SORT_NUMERIC - compare items numerically
  • SORT_STRING - compare items as strings
  • SORT_LOCALE_STRING - compare items as strings, based on the current locale.

So maybe its just that param you need:

$imports = array_unique($imports, SORT_REGULAR);
user5542121
  • 1,051
  • 12
  • 28