Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Created November 6, 2015 16:49
Show Gist options
  • Select an option

  • Save jessepearson/dd36961791d459db0697 to your computer and use it in GitHub Desktop.

Select an option

Save jessepearson/dd36961791d459db0697 to your computer and use it in GitHub Desktop.
<?php
// go through possible packages
foreach ( $possible_packages as $package ) {
// add the best to a new array
if ( $package->percent == $best_percent ) {
$best_packages[] = $package;
}
}
// if there's only one, that's our package
if ( 1 == count( $best_packages ) ) {
$best_package = $best_packages[0];
} else {
// if more, go through each
foreach ( $best_packages as $package ) {
// get the lowest volume (smallest box)
$lowest_volume = ( isset( $lowest_volume ) ) ? $lowest_volume : $package->box_vol;
// and set the smallest box as the best package
if ( $lowest_volume >= $package->box_vol ) {
$best_package = $package;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment