summaryrefslogtreecommitdiffstats
path: root/system/helpers/array_helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/helpers/array_helper.php')
-rwxr-xr-x[-rw-r--r--]system/helpers/array_helper.php52
1 files changed, 46 insertions, 6 deletions
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php
index b7289900f..6b2415df2 100644..100755
--- a/system/helpers/array_helper.php
+++ b/system/helpers/array_helper.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -38,7 +38,7 @@
* @param array
* @param mixed
* @return mixed depends on what the array contains
- */
+ */
if ( ! function_exists('element'))
{
function element($item, $array, $default = FALSE)
@@ -49,7 +49,7 @@ if ( ! function_exists('element'))
}
return $array[$item];
- }
+ }
}
// ------------------------------------------------------------------------
@@ -60,7 +60,7 @@ if ( ! function_exists('element'))
* @access public
* @param array
* @return mixed depends on what the array contains
- */
+ */
if ( ! function_exists('random_element'))
{
function random_element($array)
@@ -70,9 +70,49 @@ if ( ! function_exists('random_element'))
return $array;
}
return $array[array_rand($array)];
- }
+ }
}
+// --------------------------------------------------------------------
+
+/**
+ * Elements
+ *
+ * Returns only the array items specified. Will return a default value if
+ * it is not set.
+ *
+ * @access public
+ * @param array
+ * @param array
+ * @param mixed
+ * @return mixed depends on what the array contains
+ */
+if ( ! function_exists('elements'))
+{
+ function elements($items, $array, $default = FALSE)
+ {
+ $return = array();
+
+ if ( ! is_array($items))
+ {
+ $items = array($items);
+ }
+
+ foreach ($items as $item)
+ {
+ if (isset($array[$item]))
+ {
+ $return[$item] = $array[$item];
+ }
+ else
+ {
+ $return[$item] = $default;
+ }
+ }
+
+ return $return;
+ }
+}
/* End of file array_helper.php */
/* Location: ./system/helpers/array_helper.php */ \ No newline at end of file