blob: 82f0eb16cebeaf608f7b55b970d070f566e38dde [file] [log] [blame]
Andrey Andreevf1b43d42012-01-06 14:41:50 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreevf1b43d42012-01-06 14:41:50 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevf1b43d42012-01-06 14:41:50 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
Andrey Andreev63a21002012-01-19 15:13:32 +020012 * bundled with this package in the files license.txt / license.rst. It is
Derek Jonesf4a4bd82011-10-20 12:18:42 -050013 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * CodeIgniter Array Helpers
30 *
31 * @package CodeIgniter
32 * @subpackage Helpers
33 * @category Helpers
Derek Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/helpers/array_helper.html
36 */
37
38// ------------------------------------------------------------------------
39
40/**
41 * Element
42 *
43 * Lets you determine whether an array index is set and whether it has a value.
44 * If the element is empty it returns FALSE (or whatever you specify as the default value.)
45 *
46 * @access public
47 * @param string
48 * @param array
49 * @param mixed
50 * @return mixed depends on what the array contains
Barry Mienydd671972010-10-04 16:33:58 +020051 */
Derek Allard2067d1a2008-11-13 22:59:24 +000052if ( ! function_exists('element'))
53{
54 function element($item, $array, $default = FALSE)
55 {
Andrey Andreev63a21002012-01-19 15:13:32 +020056 return ( ! isset($array[$item]) OR $array[$item] == '') ? $default : $array[$item];
Barry Mienydd671972010-10-04 16:33:58 +020057 }
Derek Allard2067d1a2008-11-13 22:59:24 +000058}
59
60// ------------------------------------------------------------------------
61
62/**
63 * Random Element - Takes an array as input and returns a random element
64 *
65 * @access public
66 * @param array
67 * @return mixed depends on what the array contains
Barry Mienydd671972010-10-04 16:33:58 +020068 */
Derek Allard2067d1a2008-11-13 22:59:24 +000069if ( ! function_exists('random_element'))
70{
71 function random_element($array)
72 {
Andrey Andreev63a21002012-01-19 15:13:32 +020073 return is_array($array) ? $array[array_rand($array)] : $array;
Barry Mienydd671972010-10-04 16:33:58 +020074 }
Derek Allard2067d1a2008-11-13 22:59:24 +000075}
76
Derek Jones3a082fd2010-10-07 09:38:55 -050077// --------------------------------------------------------------------
78
79/**
80 * Elements
81 *
Derek Jones37f4b9c2011-07-01 17:56:50 -050082 * Returns only the array items specified. Will return a default value if
Derek Jones3a082fd2010-10-07 09:38:55 -050083 * it is not set.
84 *
85 * @access public
86 * @param array
87 * @param array
88 * @param mixed
89 * @return mixed depends on what the array contains
90 */
91if ( ! function_exists('elements'))
92{
93 function elements($items, $array, $default = FALSE)
94 {
95 $return = array();
Derek Jones3a082fd2010-10-07 09:38:55 -050096 if ( ! is_array($items))
97 {
98 $items = array($items);
99 }
Andrey Andreevf1b43d42012-01-06 14:41:50 +0200100
Derek Jones3a082fd2010-10-07 09:38:55 -0500101 foreach ($items as $item)
102 {
Andrey Andreev63a21002012-01-19 15:13:32 +0200103 $return[$item] = isset($array[$item]) ? $array[$item] : $default;
Derek Jones3a082fd2010-10-07 09:38:55 -0500104 }
105
106 return $return;
107 }
108}
Derek Allard2067d1a2008-11-13 22:59:24 +0000109
110/* End of file array_helper.php */
Andrey Andreevf1b43d42012-01-06 14:41:50 +0200111/* Location: ./system/helpers/array_helper.php */