summaryrefslogtreecommitdiffstats
path: root/system/helpers/array_helper.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:51:06 +0100
committerFlorian Pritz <bluewind@server-speed.net>2011-01-28 22:58:52 +0100
commitce2b69675075444c9e40b72bcdd42ab7edbbe633 (patch)
tree2932f13b0db14fe53dc0622d888318db638a017f /system/helpers/array_helper.php
parentb6b8a6587c399bfd89e13e92ce04ee8486688e6e (diff)
update to CI 2.0
Signed-off-by: Florian Pritz <bluewind@server-speed.net>
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