note 98048 modified in function.max by visualmind

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
max() on undefined parameters does not assume the value is zero, it ignores it.
<?php
$dimensions = array('left' => -2);
// If $dimensions['right'] was never set, 
// we may expect it to be treated as zero, but
print max($dimensions['left'], $dimensions['right']);
//
// Returns -2, not zero

print max(0+$dimensions['left'], 0+$dimensions['right']);
?>
would be a work-around, but it's probably tidier to ensure your values are set correctly first.

(on PHP 5.2.11 anyway)

--was--
max() on undefined parameters does not assume the value is zero, it ignores it.
<?php
$dimensions = array('left' => -2);
// If $dimensions['right'] was never set, 
// we may expect it to be treated as zero, but
print max($dimensions['left'], $dimensions['right']);
//
// Returns -2, not zero

<?php
print max(0+$dimensions['left'], 0+$dimensions['right']);
?>
would be a work-around, but it's probably tidier to ensure your values are set correctly first.

(on PHP 5.2.11 anyway)

http://php.net/manual/en/function.max.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.