Skip to content

Instantly share code, notes, and snippets.

@gormus
Created June 16, 2016 03:33
Show Gist options
  • Select an option

  • Save gormus/1fbfd0107149c03ba145f7ed40c82029 to your computer and use it in GitHub Desktop.

Select an option

Save gormus/1fbfd0107149c03ba145f7ed40c82029 to your computer and use it in GitHub Desktop.
Unset an item from an array by its value.
<?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