3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function base26($value) { $name = ''; for ($exponent = 0; $value > 0 && pow(26, $exponent) <= $value; $exponent++) { $digitValue = intval(pow(26, $exponent)); $remainder = $value % intval(pow(26, $exponent + 1)); $ascii = 64 + intval($remainder / $digitValue); $name = chr($ascii) . $name; echo sprintf("value: %d, remainder: %d\n", $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
value: 1, remainder: 1 1->A value: 2, remainder: 2 2->B value: 3, remainder: 3 3->C value: 4, remainder: 4 4->D value: 5, remainder: 5 5->E value: 6, remainder: 6 6->F value: 7, remainder: 7 7->G value: 8, remainder: 8 8->H value: 9, remainder: 9 9->I value: 10, remainder: 10 10->J value: 11, remainder: 11 11->K value: 12, remainder: 12 12->L value: 13, remainder: 13 13->M value: 14, remainder: 14 14->N value: 15, remainder: 15 15->O value: 16, remainder: 16 16->P value: 17, remainder: 17 17->Q value: 18, remainder: 18 18->R value: 19, remainder: 19 19->S value: 20, remainder: 20 20->T value: 21, remainder: 21 21->U value: 22, remainder: 22 22->V value: 23, remainder: 23 23->W value: 24, remainder: 24 24->X value: 25, remainder: 25 25->Y value: 26, remainder: 0 value: 26, remainder: 26 26->A@ value: 27, remainder: 1 value: 26, remainder: 26 27->AA