From b0277b6c03fc0bc2348797796a2605861d6200bb Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Fri, 3 Feb 2012 23:43:45 +0000 Subject: [PATCH] functions.inc.php - new function remove_from_array() git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1343 a1433add-5e2c-0410-b055-b7f2511e0802 --- functions.inc.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/functions.inc.php b/functions.inc.php index c172612c..2ed06192 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1262,6 +1262,23 @@ function hex2bin ($str) { } return $nstr; } + +/* + * remove item $item from array $array + */ +function remove_from_array($array, $item) { + # array_diff might be faster, but doesn't provide an easy way to know if the value was found or not + # return array_diff($array, array($item)); + $ret = array_search($item, $array); + if ($ret === false) { + $found = 0; + } else { + $found = 1; + unset ($array[$ret]); + } + return array($found, $array); +} + /**/ } function to64 ($v, $n) {