blob: 6f56d9db9a22f4ef992c8f766d23f099258381c6 [file] [log] [blame]
Andrey Andreeve5617332012-03-13 12:22:17 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreeve5617332012-03-13 12:22:17 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreeve5617332012-03-13 12:22:17 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * 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 *
Derek Allard2067d1a2008-11-13 22:59:24 +000046 * @param string
47 * @param array
48 * @param mixed
49 * @return mixed depends on what the array contains
Barry Mienydd671972010-10-04 16:33:58 +020050 */
Derek Allard2067d1a2008-11-13 22:59:24 +000051if ( ! function_exists('element'))
52{
53 function element($item, $array, $default = FALSE)
54 {
Andrey Andreeve5617332012-03-13 12:22:17 +020055 return empty($array[$item]) ? $default : $array[$item];
Barry Mienydd671972010-10-04 16:33:58 +020056 }
Derek Allard2067d1a2008-11-13 22:59:24 +000057}
58
59// ------------------------------------------------------------------------
60
61/**
62 * Random Element - Takes an array as input and returns a random element
63 *
Derek Allard2067d1a2008-11-13 22:59:24 +000064 * @param array
65 * @return mixed depends on what the array contains
Barry Mienydd671972010-10-04 16:33:58 +020066 */
Derek Allard2067d1a2008-11-13 22:59:24 +000067if ( ! function_exists('random_element'))
68{
69 function random_element($array)
70 {
Andrey Andreeve5617332012-03-13 12:22:17 +020071 return is_array($array) ? $array[array_rand($array)] : $array;
Barry Mienydd671972010-10-04 16:33:58 +020072 }
Derek Allard2067d1a2008-11-13 22:59:24 +000073}
74
Derek Jones3a082fd2010-10-07 09:38:55 -050075// --------------------------------------------------------------------
76
77/**
78 * Elements
79 *
Andrey Andreeve5617332012-03-13 12:22:17 +020080 * Returns only the array items specified. Will return a default value if
Derek Jones3a082fd2010-10-07 09:38:55 -050081 * it is not set.
82 *
Derek Jones3a082fd2010-10-07 09:38:55 -050083 * @param array
84 * @param array
85 * @param mixed
86 * @return mixed depends on what the array contains
87 */
88if ( ! function_exists('elements'))
89{
90 function elements($items, $array, $default = FALSE)
91 {
92 $return = array();
Andrey Andreeve5617332012-03-13 12:22:17 +020093
94 is_array($items) OR $items = array($items);
95
Derek Jones3a082fd2010-10-07 09:38:55 -050096 foreach ($items as $item)
97 {
Andrey Andreeve5617332012-03-13 12:22:17 +020098 $return[$item] = isset($array[$item]) ? $array[$item] : $default;
Derek Jones3a082fd2010-10-07 09:38:55 -050099 }
100
101 return $return;
102 }
103}
Derek Allard2067d1a2008-11-13 22:59:24 +0000104
105/* End of file array_helper.php */
Andrey Andreeve6f7d612012-03-20 15:39:22 +0200106/* Location: ./system/helpers/array_helper.php */