1

Here is the description of array_unique() in PHP 7.2:

If sort_flags is SORT_STRING, formerly array has been copied and non-unique elements have been removed (without packing the array afterwards), but now a new array is built by adding the unique elements. This can result in different numeric indexes.

I have done many examples to see if there are any difference but can't. Could anyone please help show me the changes? Thank you.

TungPS
  • 51
  • 6
  • I think this means that instead of `[b, c, c, d]` becoming `[0 => b, 1 => c, 3 => d]`, you get `[b, c, d]` – Andrea Dec 07 '18 at 18:39
  • @Andrea Can you please show me the site that return result like yours? Because I ran on many PHP online site but they return the same result in all PHP version: it is always [0 => b, 1 => c, 3 => d] – TungPS Dec 10 '18 at 01:46
  • Hmm. Using 3v4l.org I can't figure out what the change is, I'm as confused as you! I'll go investigate in the source code. – Andrea Dec 10 '18 at 20:28
  • 1
    I think this is about this change: https://github.com/php/php-src/commit/6c2c7a023da4223e41fea0225c51a417fc8eb10d - That's by @NikiC who is active here on StackOverflow, so I've pinged him about it. – Andrea Dec 10 '18 at 20:33
  • 2
    @Andrea Only possible differences in behavior I can imagine here are wrt implicit array state such as IAP and next free element, which will no longer be preserved. The indexes in the array itself should still be the same though. Most likely this is referring to next free element not being preserved, but it's not clear from the description. – NikiC Dec 10 '18 at 21:51
  • 1
    @NikiC Thank you so much for helping! If you want to, you can post your answer so I can mark it as the answer to the problem. – TungPS Dec 11 '18 at 01:30
  • @NikiC Worth me updating the documentation to be clearer then? – Andrea Dec 11 '18 at 22:28
  • 1
    @Andrea I think so! The current note really makes no sense. – NikiC Dec 12 '18 at 10:24

0 Answers0