Skip to content

Instantly share code, notes, and snippets.

@oropesa
Last active August 29, 2015 14:06
Show Gist options
  • Save oropesa/86f1ab370857209b57c3 to your computer and use it in GitHub Desktop.
Save oropesa/86f1ab370857209b57c3 to your computer and use it in GitHub Desktop.
Add and remove elements from an array. It uses the function string2array()
<?php
/**
* Use:
* $array = ('Hi', 'World')
* $array = manageArray('Foo, Bar Foobar', 'World');
* // output:
* // $array = ('Hi', 'Foo', 'Bar', 'Foobar')
*/
function easyArrayManage ($array, $addElements = '', $removeElements = '') {
//add
$array = array_merge( $array, string2array($addElements) );
//remove
$array = array_diff( $array, string2array($removeElements) );
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment