$letter = array();
for ($i = 'A'; $i !== 'ZZ'; $i++){
$letter[] .= $i;
}
print_r($letter);
From above script I do a loop from A
, B
, C
, D
... ZZ
.
Now, I want to make it as A
, C
, E
, G
, I
... ZZ
. (2 steps instead of 1)
I need direction to do it.
ord()
will not work because your end string is two characters long.Watch it break.
From my testing, you need to check that the
end
string doesn't get "stepped over". The perl-style character incrementation is a cool method, but it is a single-stepping method. For this reason, an inner loop helps it along when necessary. This is actually not a bother, in fact, it is useful because we need to check if the loop(s) should be broken on each single step.Code: (Demo)
Output:
Here is an array-functions approach:
Code: (Demo)
Output:
Here is your solution for the problem,
You need to get the ASCII value for that character which will solve your problem.
Here is ord doc and working code.
For your requirement, you can do like this,
Here set $x as per your requirement.