3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function base26($value) { $name = ''; for ($exponent = 0; pow(26, $exponent) <= $value; $exponent++) { $digitWeight = intval(pow(26, $exponent)); $remainder = $value % intval(pow(26, $exponent + 1)); $digitValue = intval($remainder / $digitWeight); $ascii = 64 + $digitValue; $name = chr($ascii) . $name; echo sprintf("digitValue: %d, ascii: %d, value: %d, remainder: %d\n", $digitValue, $ascii, $value, $remainder); $value -= $remainder; } return $name; } for ($i = 1; $i < 28; $i++) { echo $i . "->" . base26($i) . "\n"; }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
digitValue: 1, ascii: 65, value: 1, remainder: 1 1->A digitValue: 2, ascii: 66, value: 2, remainder: 2 2->B digitValue: 3, ascii: 67, value: 3, remainder: 3 3->C digitValue: 4, ascii: 68, value: 4, remainder: 4 4->D digitValue: 5, ascii: 69, value: 5, remainder: 5 5->E digitValue: 6, ascii: 70, value: 6, remainder: 6 6->F digitValue: 7, ascii: 71, value: 7, remainder: 7 7->G digitValue: 8, ascii: 72, value: 8, remainder: 8 8->H digitValue: 9, ascii: 73, value: 9, remainder: 9 9->I digitValue: 10, ascii: 74, value: 10, remainder: 10 10->J digitValue: 11, ascii: 75, value: 11, remainder: 11 11->K digitValue: 12, ascii: 76, value: 12, remainder: 12 12->L digitValue: 13, ascii: 77, value: 13, remainder: 13 13->M digitValue: 14, ascii: 78, value: 14, remainder: 14 14->N digitValue: 15, ascii: 79, value: 15, remainder: 15 15->O digitValue: 16, ascii: 80, value: 16, remainder: 16 16->P digitValue: 17, ascii: 81, value: 17, remainder: 17 17->Q digitValue: 18, ascii: 82, value: 18, remainder: 18 18->R digitValue: 19, ascii: 83, value: 19, remainder: 19 19->S digitValue: 20, ascii: 84, value: 20, remainder: 20 20->T digitValue: 21, ascii: 85, value: 21, remainder: 21 21->U digitValue: 22, ascii: 86, value: 22, remainder: 22 22->V digitValue: 23, ascii: 87, value: 23, remainder: 23 23->W digitValue: 24, ascii: 88, value: 24, remainder: 24 24->X digitValue: 25, ascii: 89, value: 25, remainder: 25 25->Y digitValue: 0, ascii: 64, value: 26, remainder: 0 digitValue: 1, ascii: 65, value: 26, remainder: 26 26->A@ digitValue: 1, ascii: 65, value: 27, remainder: 1 digitValue: 1, ascii: 65, value: 26, remainder: 26 27->AA