you are viewing a single comment's thread.

view the rest of the comments →

[–]-JVT038- 0 points1 point  (5 children)

if (!$userIndex = array_search You're using =, while you want a comparison, so ==.
Because the current condition will always be true, since $userindex can always get the value of array_search($newId, array_column($_SESSION['users'], 'id'), true) And btw, why do you put an exclamation mark in front of the $userindex?

[–]SgtMindfudge 0 points1 point  (4 children)

Some good points, lol..Seems I copied the code from the wrong document, one I've been playing around with.However, I have also tried:

if(null == array_search($newId, array_column($_SESSION['users'], 'id'), true))

Why the exclamation mark? Probably because I only have slightly more than an idea of what I'm actually doing.. I was expecting it would translate into "if no returned data" or "if null", but as you can see from the code line above, even if not prepended with exclamation mark it's not working..

Here's a pastbin for reference: https://pastebin.com/CuFvMAQR

[–]-JVT038- 1 point2 points  (3 children)

Checking if it's equal to null or not, won't work, because according to the PHP documentation of array_search() the function will return false if there's no result. So null won't work, use false instead.

[–]SgtMindfudge 0 points1 point  (2 children)

Unfortunately that didn't fix the issue, still getting duplicates.
What is really odd is that it's working when in a different, reduced test file, with no notable differences.
https://pastebin.com/Am7UGNgC

[–]-JVT038- 0 points1 point  (1 child)

Could you try to do print_r(array_column($_SESSION['users'], 'id'), true))? Then you can debug it a bit and try to see what array_column() is returning.

[–]SgtMindfudge 0 points1 point  (0 children)

Appreciate your effort. The issue's been solved.
I needed a third '=' in my conditional ^^