Codice:
<?php
$dispari = array(1,2,3,4,5,'A');
for($i = 0; $i <= 5; $i++) {
$temp = $dispari[$i];
if($temp == 0) {
$endispari[] = 0;
} else if($temp == 1) {
$endispari[] = 1;
} else if($temp == 2) {
$endispari[] = 2;
} else if($temp == 3) {
$endispari[] = 3;
} else if($temp == 4) {
$endispari[] = 4;
} else if($temp == 5) {
$endispari[] = 5;
} else if($temp == 6) {
$endispari[] = 6;
} else if($temp == 7) {
$endispari[] = 7;
} else if($temp == 8) {
$endispari[] = 8;
} else if($temp == 9) {
$endispari[] = 9;
} else if($temp == "A") {
$endispari[] = 0;
} else if($temp == "B") {
$endispari[] = 1;
} else if($temp == "C") {
$endispari[] = 2;
} else if($temp == "D") {
$endispari[] = 3;
} else if($temp == "E") {
$endispari[] = 4;
} else if($temp == "F") {
$endispari[] = 5;
} else if($temp == "G") {
$endispari[] = 6;
} else if($temp == "H") {
$endispari[] = 7;
} else if($temp == "I") {
$endispari[] = 8;
} else if($temp == "J") {
$endispari[] = 9;
} else if($temp == "K") {
$endispari[] = 10;
} else if($temp == "L") {
$endispari[] = 11;
} else if($temp == "M") {
$endispari[] = 12;
} else if($temp == "N") {
$endispari[] = 13;
} else if($temp == "O") {
$endispari[] = 14;
} else if($temp == "P") {
$endispari[] = 15;
} else if($temp == "Q") {
$endispari[] = 16;
} else if($temp == "R") {
$endispari[] = 17;
} else if($temp == "S") {
$endispari[] = 18;
} else if($temp == "T") {
$endispari[] = 19;
} else if($temp == "U") {
$endispari[] = 20;
} else if($temp == "V") {
$endispari[] = 21;
} else if($temp == "W") {
$endispari[] = 22;
} else if($temp == "X") {
$endispari[] = 23;
} else if($temp == "Y") {
$endispari[] = 24;
} else {
$endispari[] = 25;
}
}
$sommadispari = array_sum($endispari);
echo "$sommadispari";
?>
output 15, $endispari ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 0 )
a cosa serva, rimane un mistero