Last active
December 5, 2019 19:50
-
-
Save kajstrom/241ee0db440940a13746fec9ecf8dd6b to your computer and use it in GitHub Desktop.
Delete an item from an array without a loop if you don't know the index of the item
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$items = [1, 2, 3, 4]; | |
$itemToDelete = 3; | |
$itemsWithout3 = array_values(array_diff($items, [$itemToDelete])); | |
//$itemsWithout3 => [1, 2, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment