Created
February 5, 2015 09:10
-
-
Save bacanu/81ff5da685ed54da0be2 to your computer and use it in GitHub Desktop.
tabel cu litere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $chars = array( | |
| 'a', 'x', 'y', 'f', | |
| 'a', 'x', 'y', 'f', | |
| 'a', 'x', 'y', 'f', | |
| 'a', 'x', 'y', 'f' | |
| ); | |
| // sa zicem ca chars are 81 de litere in el, | |
| // doar 1 litera este cea pe care o vrei tu | |
| // si care nu are dublura | |
| // 81 este 9 la puterea a 2a | |
| // sau 9 = radical din 81 | |
| // tu trebuie sa ai 9 randuri si 9 coloane | |
| // poti sa aplici pentru orice numar ca sa afli randuri si coloane | |
| // ex radical din 400 = 20 (randuri si coloane) | |
| $rows = sqrt(count($chars)); // sqrt() e radical, acum trebuie si count($chars) sa fie un patrat | |
| $cols = $rows; //pentru ca sunt acelasi numar | |
| $index = 0; //asta numara ce caracter trebuie sa arati | |
| echo "<table border='1'>"; | |
| for ( $i = 0; $i < $rows; $i++ ) | |
| { | |
| echo "<tr>"; //incepi randul | |
| for ( $j = 0; $j < $cols; $j++ ){ | |
| echo "<td>".$chars[$index]."</td>"; // scrii coloana | |
| //vor fi $cols coloane | |
| $index++; // asta o sa ajunga de la 0 la (count($chars) - 1) | |
| // creste de fiecare data cand scrii un caracter | |
| } | |
| echo "</tr>"; //termini randul | |
| // vor fi $rows randuri | |
| } | |
| echo "</table>"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment