+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
* Provides a collection of static methods for array manipulation.
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
*/
class CRM_Utils_Array {
}
/**
- * convert associative array names to values
+ * convert associative array names to values.
* and vice-versa.
*
* This function is used by both the web form layer and the api. Note that
* @param array $items
* The array from which to remove items.
*
- * @internal param string|\string[] $key When passed a string, unsets $items[$key].* When passed a string, unsets $items[$key].
- * When passed an array of strings, unsets $items[$k] for each string $k
- * in the array.
+ * Additional params:
+ * When passed a string, unsets $items[$key].
+ * When passed an array of strings, unsets $items[$k] for each string $k in the array.
*/
public static function remove(&$items) {
foreach (func_get_args() as $n => $key) {
if (is_array($values)) {
return $values;
}
+ // Empty string -> empty array
+ if ($values === '') {
+ return array();
+ }
return explode($delim, trim((string) $values, $delim));
}
}
/**
- * Get the first element of an array
+ * Get the first element of an array.
*
* @param array $array
* @return mixed|NULL
}
return $output;
}
+
+ /**
+ * Diff multidimensional arrays
+ * ( array_diff does not support multidimensional array)
+ *
+ * @param array $array1
+ * @param array $array2
+ * @return array
+ */
+ public static function multiArrayDiff($array1, $array2) {
+ $arrayDiff = array();
+ foreach ($array1 as $mKey => $mValue) {
+ if (array_key_exists($mKey, $array2)) {
+ if (is_array($mValue)) {
+ $recursiveDiff = self::multiArrayDiff($mValue, $array2[$mKey]);
+ if (count($recursiveDiff)) {
+ $arrayDiff[$mKey] = $recursiveDiff;
+ }
+ }
+ else {
+ if ($mValue != $array2[$mKey]) {
+ $arrayDiff[$mKey] = $mValue;
+ }
+ }
+ }
+ else {
+ $arrayDiff[$mKey] = $mValue;
+ }
+ }
+ return $arrayDiff;
+ }
+
}