diff options
author | Jamie Rumbelow <jamie@jamierumbelow.net> | 2012-04-26 14:27:35 +0200 |
---|---|---|
committer | Jamie Rumbelow <jamie@jamierumbelow.net> | 2012-04-26 14:27:35 +0200 |
commit | d6ce1e936d60487ad8ddd099a040fba7d8f88367 (patch) | |
tree | 31dcdda9a24e2ed12135659a4e38cb4f35b0af31 /system/helpers/array_helper.php | |
parent | bcee50ff3247dee71d83bf273e52bc10096cd48c (diff) | |
parent | 9e2d5d130eff40592b49337a8ba4d8c170934de1 (diff) |
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into develop
Conflicts:
system/core/Loader.php
system/database/DB_query_builder.php
system/database/drivers/cubrid/cubrid_driver.php
system/database/drivers/mssql/mssql_driver.php
system/database/drivers/mysql/mysql_driver.php
system/database/drivers/mysqli/mysqli_driver.php
system/database/drivers/oci8/oci8_driver.php
system/database/drivers/odbc/odbc_driver.php
system/database/drivers/pdo/pdo_driver.php
system/database/drivers/postgre/postgre_driver.php
system/database/drivers/sqlite/sqlite_driver.php
user_guide_src/source/changelog.rst
user_guide_src/source/database/query_builder.rst
Diffstat (limited to 'system/helpers/array_helper.php')
-rw-r--r-- | system/helpers/array_helper.php | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/system/helpers/array_helper.php b/system/helpers/array_helper.php index c46c4d103..6f56d9db9 100644 --- a/system/helpers/array_helper.php +++ b/system/helpers/array_helper.php @@ -1,13 +1,13 @@ -<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); +<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE - * + * * Licensed under the Open Software License version 3.0 - * + * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * CodeIgniter Array Helpers * @@ -45,7 +43,6 @@ * Lets you determine whether an array index is set and whether it has a value. * If the element is empty it returns FALSE (or whatever you specify as the default value.) * - * @access public * @param string * @param array * @param mixed @@ -55,12 +52,7 @@ if ( ! function_exists('element')) { function element($item, $array, $default = FALSE) { - if ( ! isset($array[$item]) OR $array[$item] == "") - { - return $default; - } - - return $array[$item]; + return empty($array[$item]) ? $default : $array[$item]; } } @@ -69,7 +61,6 @@ if ( ! function_exists('element')) /** * Random Element - Takes an array as input and returns a random element * - * @access public * @param array * @return mixed depends on what the array contains */ @@ -77,12 +68,7 @@ if ( ! function_exists('random_element')) { function random_element($array) { - if ( ! is_array($array)) - { - return $array; - } - - return $array[array_rand($array)]; + return is_array($array) ? $array[array_rand($array)] : $array; } } @@ -91,10 +77,9 @@ if ( ! function_exists('random_element')) /** * Elements * - * Returns only the array items specified. Will return a default value if + * Returns only the array items specified. Will return a default value if * it is not set. * - * @access public * @param array * @param array * @param mixed @@ -105,22 +90,12 @@ if ( ! function_exists('elements')) function elements($items, $array, $default = FALSE) { $return = array(); - - if ( ! is_array($items)) - { - $items = array($items); - } - + + is_array($items) OR $items = array($items); + foreach ($items as $item) { - if (isset($array[$item])) - { - $return[$item] = $array[$item]; - } - else - { - $return[$item] = $default; - } + $return[$item] = isset($array[$item]) ? $array[$item] : $default; } return $return; |