I am working with user supplied dimensions on a variety of products. Users supplied the length, width and height, but to calculate shipping costs I have take the longest measurement and set it as length and add that to the girth, which is calculated by adding the two shorter measurements and multiplying them by 2.
$PackageSize = length + (width*2 + height*2)
$newlength=max($length, $width, $height);
To me, the easiest way to do this is to leverage PHP's awesome array functions.
// create an array from the three dimensions $sizes = array( $length, $width, $height ); // sorts the values from smallest to largest sort( $sizes ); // assigns the sorted values to the variables width, height, length list( $width, $height, $length ) = $sizes; // Now, $length is the longest dimension, $width is shortest, and $height is the middle value