Source for file array_functions.php

Documentation is available at array_functions.php

  1. <?php
  2. /**
  3.  * CodeIgniter
  4.  *
  5.  * An open source application development framework for PHP 4.3.2 or newer
  6.  *
  7.  * @package        CodeIgniter
  8.  * @subpackage     Helpers
  9.  * @author        ExpressionEngine Dev Team
  10.  * @copyright    Copyright (c) 2006, EllisLab, Inc.
  11.  * @license        http://codeigniter.com/user_guide/license.html
  12.  * @link        http://codeigniter.com
  13.  * @since        Version 1.0
  14.  * @filesource
  15.  */
  16.  
  17. // ------------------------------------------------------------------------
  18.  
  19. /**
  20.  * CodeIgniter Array Helpers
  21.  *
  22.  * @author        ExpressionEngine Dev Team
  23.  * @link        http://codeigniter.com/user_guide/helpers/array_helper.html
  24.  */
  25.  
  26. // ------------------------------------------------------------------------
  27.  
  28. if (function_exists('element')) {
  29.     /**
  30.      * Element
  31.      *
  32.      * Lets you determine whether an array index is set and whether it has a value.
  33.      * If the element is empty it returns FALSE (or whatever you specify as the default value.)
  34.      *
  35.      * @access    public
  36.      * @param    string 
  37.      * @param    array 
  38.      * @param    mixed 
  39.      * @return    mixed    depends on what the array contains
  40.      */
  41.     function element($item$array$default FALSE)
  42.     {
  43.         if isset($array[$item]OR $array[$item== "")
  44.         {
  45.             return $default;
  46.         }
  47.  
  48.         return $array[$item];
  49.     }    
  50. }
  51.  
  52. // ------------------------------------------------------------------------
  53.  
  54.  
  55. if (function_exists('random_element')) {
  56.     /**
  57.      * Random Element - Takes an array as input and returns a random element
  58.      *
  59.      * @access    public
  60.      * @param    array 
  61.      * @return    mixed    depends on what the array contains
  62.      */    
  63.     function random_element($array)
  64.     {
  65.         if is_array($array))
  66.         {
  67.             return $array;
  68.         }
  69.         return $array[array_rand($array)];
  70.     }    
  71. }
  72.  
  73.  
  74. // ------------------------------------------------------------------------
  75.  
  76.  
  77. if (function_exists('join_recordset')) {
  78.     /**
  79.      * Random Element - Takes an array as input and returns a random element
  80.      *
  81.      * @access    public
  82.      * @param    array 
  83.      * @return    mixed    depends on what the array contains
  84.      */    
  85.     function join_recordset($cGlue$aArray$vKey{
  86.         $aRet array();
  87.         
  88.         foreach ($aArray as $item{
  89.             $aRet[$item[$vKey];
  90.         }
  91.         
  92.         return join($cGlue$aRet);
  93.     }    
  94. }
  95.  
  96. if (function_exists('trim_recursive')) {
  97.     /**
  98.      * Trims a entire array recursivly.
  99.      * 
  100.      * @author      Jonas John
  101.      * @version     0.2
  102.      * @link        http://www.jonasjohn.de/snippets/php/trim-array.htm
  103.      * @param       array      $Input      Input array
  104.      */
  105.     function trim_recursive($Input){
  106.         if (!is_array($Input)) {
  107.             return trim($Input);
  108.         }
  109.         
  110.         return array_map('trim_recursive'$Input);
  111.     }
  112. }
  113. ?>

Documentation generated on Tue, 22 Nov 2011 13:28:50 -0200 by phpDocumentor 1.4.3