Last active
August 29, 2015 14:06
-
-
Save oropesa/86f1ab370857209b57c3 to your computer and use it in GitHub Desktop.
Add and remove elements from an array. It uses the function string2array()
This file contains 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 | |
/** | |
* 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