blob: 837e41f14c3e322a9501631a5c66eb0322f870b2 [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * CodeIgniter Array Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/array_helper.html
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Element
32 *
33 * Lets you determine whether an array index is set and whether it has a value.
34 * If the element is empty it returns FALSE (or whatever you specify as the default value.)
35 *
36 * @access public
37 * @param string
38 * @param array
39 * @param mixed
40 * @return mixed depends on what the array contains
41 */
Derek Jones269b9422008-01-28 21:00:20 +000042if (! function_exists('element'))
Derek Allardd2df9bc2007-04-15 17:41:17 +000043{
Derek Jones269b9422008-01-28 21:00:20 +000044 function element($item, $array, $default = FALSE)
Derek Allardd2df9bc2007-04-15 17:41:17 +000045 {
Derek Allard73274992008-05-05 16:39:18 +000046 if (! isset($array[$item]) OR $array[$item] == "")
Derek Jones269b9422008-01-28 21:00:20 +000047 {
48 return $default;
49 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000050
Derek Jones269b9422008-01-28 21:00:20 +000051 return $array[$item];
52 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000053}
54
55// ------------------------------------------------------------------------
56
57/**
58 * Random Element - Takes an array as input and returns a random element
59 *
60 * @access public
61 * @param array
62 * @return mixed depends on what the array contains
63 */
Derek Jones269b9422008-01-28 21:00:20 +000064if (! function_exists('random_element'))
Derek Allardd2df9bc2007-04-15 17:41:17 +000065{
Derek Jones269b9422008-01-28 21:00:20 +000066 function random_element($array)
Derek Allardd2df9bc2007-04-15 17:41:17 +000067 {
Derek Allard73274992008-05-05 16:39:18 +000068 if (! is_array($array))
Derek Jones269b9422008-01-28 21:00:20 +000069 {
70 return $array;
71 }
72 return $array[array_rand($array)];
73 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000074}
75
Derek Jonesa3ffbbb2008-05-11 18:18:29 +000076
77/* End of file array_helper.php */
78/* Location: ./system/helpers/array_helper.php */