Created
June 11, 2019 14:13
-
-
Save hugeval/407410cb1e5038cc652fd2ba9ee37353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//$pattern = '/^(.*)\[(p|m|v)_(.*)\]/i'; | |
//preg_match($pattern, '331-60905/5106[p_0].JPG', $matches); | |
// | |
//var_dump($matches); | |
$orig = [2.2, 2, 0.7]; | |
$sQty = 4.2; | |
$new = array_fill(0, count($orig), 0); | |
$compare = 0; | |
foreach ($orig as $key => $item) { | |
$compare += $item; | |
if ($compare <= $sQty) { | |
$new[$key] = $item; | |
} else { | |
$diff = $compare - $sQty; | |
$new[$key] = $item - $diff; | |
break; | |
} | |
} | |
var_dump($new); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment