blob: 491c61577f969ba393eb863e46676e7600b311ca [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
admine334c472006-10-21 19:44:22 +000010 * @license http://www.codeignitor.com/user_guide/license.html
adminb0dd10f2006-08-25 17:25:49 +000011 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
admine334c472006-10-21 19:44:22 +000015
adminb0dd10f2006-08-25 17:25:49 +000016// ------------------------------------------------------------------------
17
18/**
19 * Code Igniter Array Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
24 * @author Rick Ellis
25 * @link http://www.codeigniter.com/user_guide/helpers/array_helper.html
26 */
27
28// ------------------------------------------------------------------------
29
30/**
admin402ddf42006-09-20 18:57:05 +000031 * Element
32 *
33 * Lets you determine whether an array index is set and whether it has a value.
admine7e1dcd2006-10-21 18:04:01 +000034 * If the element is empty it returns FALSE (or whatever you specify as the default value.)
admin402ddf42006-09-20 18:57:05 +000035 *
36 * @access public
37 * @param string
38 * @param array
39 * @param mixed
40 * @return mixed depends on what the array contains
41 */
42function element($item, $array, $default = FALSE)
43{
44 if ( ! isset($array[$item]) OR $array[$item] == "")
45 {
46 return $default;
47 }
48
49 return $array[$item];
50}
51
52// ------------------------------------------------------------------------
53
54/**
adminb0dd10f2006-08-25 17:25:49 +000055 * Random Element - Takes an array as input and returns a random element
56 *
57 * @access public
58 * @param array
59 * @return mixed depends on what the array contains
60 */
61function random_element($array)
62{
63 if ( ! is_array($array))
64 {
65 return $array;
66 }
67 return $array[array_rand($array)];
68}
69
70
71?>