3
I’m making a script to separate odd number and even number of an array
inserted via form option, and make specific calculation on them (to separate odd number from pair array
I’m 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 to a multiple number of 10?
EXAMPLE: final result: 135
to be multiple of 10, missing 5 , totals 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 odd and even number filter logic correct? And how do I identify in my final result how much longer for the number to be multiple of 10?
I tried to use round
, but it is vacant.
You can give an example of the input array?
– Sergio