P
P
Pavel2021-06-07 09:27:12
PHP
Pavel, 2021-06-07 09:27:12

Why did array_unique stop working?

asked a question Which array diff function to apply?
everything on the site worked like clockwork, but after a while (THAT WERE NOT CHANGING AT ALL IN THE CODE AND IN THE DB) and here you are...

$result gives a bunch of heaps of duplicates
through var_dump, I checked both arrays, they are the same in structure, errors, respectively no, how to understand why there are duplicates? The code did work...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2021-06-07
@mrusklon

And the whole problem is that you don't understand what "your" code does.
And therefore, you cannot debug it.
This is about the question of how easy and pleasant it is to be a programmer when others write the code for you.
Well, here it came to you in return, it's "nice"
The original problem is algorithmically primitive
And in order not to solve it, you must not be a programmer at all.
Therefore, now you need to either get together and solve the problem yourself , having thought through the algorithm and implementing it with simple means - loops and conditional transitions. Without any beautiful words like array_diff, array_filter and others. Because you can use syntactic sugar only when you understand how it works inside.If you do not understand, then the code must be written by hand, and not by magical functions.
And after that, understanding how your code works, you can debug it, run it, and display intermediate results.
Or, if it doesn't work out, then sell the computer and go to work at McDonald's.
But this is how it is with you now - "oh, one kind uncle wrote me a code, but it doesn't work, let another kind uncle fix it for me" - this will not work. They will help you twice, but you will not be able to constantly live by someone else's work. And no one needs a "programmer" who cannot write code more complicated than the "vile muescuel fetch array" level.
what is array_filter? This is an implementation of a primitive loop,

foreach ($array as $key => $value) {
    if (!условие фильтра) {
        unset($array[$key]);
    }
}

what is array_diff? This is an implementation of a slightly more complex algorithm, when we iterate over the first array, and see if there is the same element in the second one. If not, then we write this value into the third one.
Etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question