array_helper.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2008, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * CodeIgniter Array Helpers
00020  *
00021  * @package             CodeIgniter
00022  * @subpackage  Helpers
00023  * @category    Helpers
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/helpers/array_helper.html
00026  */
00027 
00028 // ------------------------------------------------------------------------
00029 
00030 /**
00031  * Element
00032  *
00033  * Lets you determine whether an array index is set and whether it has a value.
00034  * If the element is empty it returns FALSE (or whatever you specify as the default value.)
00035  *
00036  * @access      public
00037  * @param       string
00038  * @param       array
00039  * @param       mixed
00040  * @return      mixed   depends on what the array contains
00041  */     
00042 if ( ! function_exists('element'))
00043 {
00044         function element($item, $array, $default = FALSE)
00045         {
00046                 if ( ! isset($array[$item]) OR $array[$item] == "")
00047                 {
00048                         return $default;
00049                 }
00050 
00051                 return $array[$item];
00052         }       
00053 }
00054 
00055 // ------------------------------------------------------------------------
00056 
00057 /**
00058  * Random Element - Takes an array as input and returns a random element
00059  *
00060  * @access      public
00061  * @param       array
00062  * @return      mixed   depends on what the array contains
00063  */     
00064 if ( ! function_exists('random_element'))
00065 {
00066         function random_element($array)
00067         {
00068                 if ( ! is_array($array))
00069                 {
00070                         return $array;
00071                 }
00072                 return $array[array_rand($array)];
00073         }       
00074 }
00075 
00076 
00077 /* End of file array_helper.php */
00078 /* Location: ./system/helpers/array_helper.php */