linea21-externals
[ class tree: linea21-externals ] [ index: linea21-externals ] [ all elements ]

Source for file common.php

Documentation is available at common.php

  1. <?php
  2. /*
  3.  * This work is hereby released into the Public Domain.
  4.  * To view a copy of the public domain dedication,
  5.  * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
  6.  * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
  7.  *
  8.  */
  9.  
  10. /**
  11.  * @package linea21.externals
  12.  * @subpackage artichow
  13.  */
  14.  
  15. /*
  16.  * Get the minimum of an array and ignore non numeric values
  17.  */
  18. function array_min($array) {
  19.  
  20.   if(is_array($array) and count($array) > 0) {
  21.  
  22.     do {
  23.       $min = array_pop($array);
  24.       if(is_numeric($min) === FALSE) {
  25.         $min = NULL;
  26.       }
  27.     } while(count($array) > 0 and $min === NULL);
  28.  
  29.     if($min !== NULL) {
  30.       $min = (float)$min;
  31.     }
  32.  
  33.     foreach($array as $value) {
  34.       if(is_numeric($value) and (float)$value < $min) {
  35.         $min = (float)$value;
  36.       }
  37.     }
  38.  
  39.     return $min;
  40.  
  41.   }
  42.  
  43.   return NULL;
  44.  
  45. }
  46.  
  47. /*
  48.  * Get the maximum of an array and ignore non numeric values
  49.  */
  50. function array_max($array) {
  51.  
  52.   if(is_array($array) and count($array) > 0) {
  53.  
  54.     do {
  55.       $max = array_pop($array);
  56.       if(is_numeric($max) === FALSE) {
  57.         $max = NULL;
  58.       }
  59.     } while(count($array) > 0 and $max === NULL);
  60.  
  61.     if($max !== NULL) {
  62.       $max = (float)$max;
  63.     }
  64.  
  65.     foreach($array as $value) {
  66.       if(is_numeric($value) and (float)$value > $max) {
  67.         $max = (float)$value;
  68.       }
  69.     }
  70.  
  71.     return $max;
  72.  
  73.   }
  74.  
  75.   return NULL;
  76.  
  77. }
  78. /*
  79.  * Define file_put_contents() if needed
  80.  */
  81. if(function_exists('file_put_contents') === FALSE) {
  82.  
  83.   function file_put_contents($file, $content) {
  84.     $fp = fopen($file, 'w');
  85.     if($fp) {
  86.       fwrite($fp, $content);
  87.       fclose($fp);
  88.     }
  89.   }
  90.  
  91. }
  92.  
  93. /*
  94.  * Change error handler
  95.  */
  96. set_error_handler('errorHandlerArtichow');
  97.  
  98. function errorHandlerArtichow($level, $message, $file, $line) {
  99.   awImage::drawError($message.' in '.$file.' on line '.$line.'.');
  100. }
  101. ?>

Documentation generated on Thu, 03 May 2012 15:03:29 +0200 by phpDocumentor 1.4.1