Created
June 16, 2016 03:33
-
-
Save gormus/1fbfd0107149c03ba145f7ed40c82029 to your computer and use it in GitHub Desktop.
Unset an item from an array by its value.
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
| <?php | |
| /** | |
| * Unset an item from an array by its value. | |
| */ | |
| function unset_byvalue(array $array = array(), $value = '') { | |
| $index = array_search($value, $array, TRUE); | |
| if ($index !== FALSE) { | |
| unset($array[$index]); | |
| } | |
| return $array; | |
| } | |
| // Usage example. | |
| // Remove `two` from the list: | |
| $classes_array = array('one', 'two', 'three'); | |
| $new_classes_array = unset_byvalue($classes, 'two'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment