Is it possible to get a range with PHP from A to ZZ*?
a b c ... aa ... zx zy zz
For me this didn't work:
range('A', 'ZZ');
It's for PHPExcel, when it gives BE as highest field i'd run through all colums. In this case i only get A, B:
range ('A', 'BE')
The range() function creates an array containing a range of elements. This function returns an array of elements from low to high. Note: If the low parameter is higher than the high parameter, the range array will be from high to low.
To display array structure and values in PHP, we can use two functions. We can use var_dump() or print_r() to display the values of an array in human-readable format or to see the output value of the program array.
The in_array() function is an inbuilt function in PHP that is used to check whether a given value exists in an array or not. It returns TRUE if the given value is found in the given array, and FALSE otherwise.
Take advantage of PHP's ability to increment characters "perl-style"
$letters = array(); $letter = 'A'; while ($letter !== 'AAA') { $letters[] = $letter++; }
But you could also use simple integer values, and take advantage of PHPExcel's built-in PHPExcel_Cell::stringFromColumnIndex() method
EDIT
From PHP 5.5, you can also use Generators to avoid actually building the array in memory
function excelColumnRange($lower, $upper) { ++$upper; for ($i = $lower; $i !== $upper; ++$i) { yield $i; } } foreach (excelColumnRange('A', 'ZZ') as $value) { echo $value, PHP_EOL; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With