I'm doing a script to separate odd number and even number from a array
entered via form option, and make specific calculation about them (to separate odd number from pair array
am using explode
and implode
to put them all on the same line, but my code is incomplete.)
My question is: How to calculate so that in the final result the value is rounded up to a multiple of 10?
EXAMPLE: end result: 135
to be a multiple of 10, 5 is missing, total 140.
Code:
<?php
//separa os numeros da entrada da array retirando espaços vazios
$numUPC = explode(',', trim(trim($final_array), ','));
//final_array gerando erro undefined, motivo variavel sem entrada (Vazia)
$UPCdigito = array();
$numUPCpar = array();
$numUPCimpar = array();
$numArredondado = array();
//filtor de numero par e impar
foreach ($numUPC as $key => $value) {
if ($key % 2 == 0) {
$numUPCpar[] = $value;
} else {
$numUPCimpar[] = $value;
}
}
$numUPCpar = implode(', ', $numUPCpar);
$numUPCimpar = implode(', ', $numUPCimpar);
//calculo
$numUPCimpar = array_sum($numUPCimpar);
$numUPCpar = array_sum($numUPCpar);
$UPCdigito = $numUPCimpar * 3;
$UPCdigito = $UPCdigito + $numUPCpar;
$numArredondado = (round($UPCdigito / 10, 0) )* 0.5
?>
Is the logic of the odd and even number filter correct? And how do I identify in my final result how much is missing for the number to be a multiple of 10?
I tried to use round
, but it's vague.