3
I have a string, for example, with 5 characters but I need the same to have 10 characters in total, I did the following code to try to get the 5 characters remaining to get a total of 10 characters:
<?php
$letras = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$numeros = '0123456789';
$tudo = $letras.$numeros;
$string = 'XXXXX';
for($i = 0; $i < strlen($tudo); $i++) {
echo $string.$tudo[$i].PHP_EOL;
}
Return:
XXXXXA
...
XXXXX9
I would like the return to be, for example, XXXXXAAAAA
, XXXXXAAAAB
and so it goes, so I made another code to try to get the exact amount of 10 characters:
<?php
$letras = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$numeros = '0123456789';
$tudo = $letras.$numeros;
$minimo = 10;
$string = 'XXXXX';
for($i = 0; $i < strlen($tudo); $i++) {
$base = $string.$tudo[$i];
for($j = 0; $j < strlen($tudo); $j++) {
$base .= $tudo[$j];
}
echo $base.PHP_EOL;
}
But the above code returned the following:
XXXXXXXAABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
...
XXXXXXX9ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
I did not understand why return to variable $tudo
rather than return the most logical result being:
XXXXXAAAAA
XXXXXAAAAB
...
XXXXX9AAAA
XXXXX9AAAB
In the codes written here, I used echo
line by line to observe the return of each attempt, but in the final code I would like to return an array, for example:
array(
'XXXXXAAAAA',
'XXXXXAAAAB',
...
)
I appreciate any solution and/ or tip!
Incredible, had never used or studied on the class
ArrayObject
. I will certainly go deeper into it! Thank you very much.– Lucky Ferreira