JS Splice Vs PHP Unset

This one cost me more time then I care to admit. Unknown to me at the time, Javascripts splice command reindexes the array it returns, PHP on the other hand doesn’t.

To replicate the same functionality in PHP simply call “array_values” and it will return your reindexed array.

JS

groups.splice(removePosition, 1);

PHP

unset($groups[$removePosition]);
$groups = array_values($groups);

Ben Squire

Read more posts by this author.

Leicestershire, United Kingdom https://squired.co.uk