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?

4
  • 1
    Post your array structure array values and errors you were facing Commented Nov 20, 2015 at 9:43
  • Can you provide a replication case on the likes of 3v4l.org ? Commented Nov 20, 2015 at 9:43
  • Show the code in foreach also Commented Nov 20, 2015 at 9:44
  • pastebin.com/Mk1mkFMf Commented Nov 20, 2015 at 9:47

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

show us your array - before applying array_unique, print_r($imports) and update your question.
Thank you guys, $imports = array_unique($imports, SORT_REGULAR); works fine for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.