note 100652 modified in function.max by thiago

From: Date: Thu, 28 Oct 2010 14:32:06 +0000
Subject: note 100652 modified in function.max by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173551@lists.php.net to get a copy of this message
If you want to test whether x lies within two bounds: <?php static function isInRange($x, $y1, $y2) { return( ($x >= min($y1, $y2)) && ($x <= max($y1, $y2)) ); } //called by: class::isInRange(10,12,2); //or $this->isInRange(10,12,2); //or (drop static) isInRange(10,12,2); //simple test function: static function unit_isInRange() { $output = array(); $inputlist[] = array(10, 12, 2, true); $inputlist[] = array(13, 12, 2, false); $inputlist[] = array(2, -2, 2, true); $inputlist[] = array(2, -8, -2, false); foreach($inputlist as $input) { $output[] = array( 'input' => array($input[0], $input[1], $input[2]), 'output' => self::isInRange($input[0],$input[1],$input[2]), 'expected' => $input[3], ); } return($output); } ?> --was-- If you want to test whether x lies within two bounds: static function isInRange($x, $y1, $y2) { return( ($x >= min($y1, $y2)) && ($x <= max($y1, $y2)) ); } called by: class::isInRange(10,12,2); or $this->isInRange(10,12,2); or (drop static) isInRange(10,12,2); simple test function: static function unit_isInRange() { $output = array(); $inputlist[] = array(10, 12, 2, true); $inputlist[] = array(13, 12, 2, false); $inputlist[] = array(2, -2, 2, true); $inputlist[] = array(2, -8, -2, false); foreach($inputlist as $input) { $output[] = array( 'input' => array($input[0], $input[1], $input[2]), 'output' => self::isInRange($input[0],$input[1],$input[2]), 'expected' => $input[3], ); } return($output); } http://php.net/manual/en/function.max.php

« previous php.notes (#173551) next »