PHP gets letters between two letters

I have two dynamic PHP variables that return two letters based on an SQL query, and for this example I will use two random fixed letters:

$firstletter = "F";
$lastletter = "A";

I need to return all the letters between the first and last letter as an array so that I can skip them. For this example, it should return F, E, D, C, B, A

Any ideas how I can do this?

+4
source share
3 answers

range() will do the following:

<?php

var_dump(range('F', 'A'));
array(6) {
  [0]=>
  string(1) "F"
  [1]=>
  string(1) "E"
  [2]=>
  string(1) "D"
  [3]=>
  string(1) "C"
  [4]=>
  string(1) "B"
  [5]=>
  string(1) "A"
}
+2
source

Try the following:

$array = range('A', 'F');
print_r($array);

for inverse values:

$array = range('A', 'F');
print_r(array_reverse($array)); 
+1
source

You need all the alphabets between the two given letters. You can use a range to get this. for example $ letters = range ('f', 'a');

0
source

Source: https://habr.com/ru/post/1665150/


All Articles