So with the introduction of single-character ranges to the range() function, the internal function tries to be "smart", and (I am inferring from behavior here) apparently checks the type of the incoming values. If one is numeric, including numeric string, then the other is treated as numeric; if it is a non-numeric string, it is treated as zero.

But.

If you pass in a numeric string in such a way that is is forced to be recognized as type string and not type numeric, range() will function quite differently.

This is a modified version of thomas' range_string() function. It's simpler, cleaner, and more robust, but it lacks the advanced features his function had, hopefully it will be of assitance to someone.

The function "range" is very useful to get an array of characters as range('C','R') does.

At work, I had to extend the function range($a,$b) to work in this special case: with two uppercase strings $a and $b, it should return all the possible strings between $a and $b.This could be used for example to get the excel column indexes.e.g. <?php range('A','AD') ==> array('A','B','C',...,'Z','AA','AB','AC','AD') ?>

Ever wanted to generate an array with a range of column names for use in Excel file related parsing?I've wrote a function that starts at the A column and adds column names up until the column you specified.

// If it was the end column that was added, return the columns.if ($column == $end_column) return $columns; }

// Add the column children.foreach ($columns as $column) {// Don't itterate if the $end_column was already set in a previous itteration. // Stop iterating if you've reached the maximum character length.if (!in_array($end_column, $columns) && strlen($column) < $length) {$new_columns = createColumnsArray($end_column, $column);// Merge the new columns which were created with the final columns array.$columns = array_merge($columns, $new_columns); } }

return $columns;}

?>

Usage:

<?php

// Return an array with all column names from A until and with BI.createColumnsArray('BI');

I needed a function, that creates a letter range with arbitrary length.You specify via the $length parameter, how many entries you need.Logic is analog to the logic of the column-titles in a calc-sheet.

so, if you want to use a non-integral step size params for numeric ranges, be sure to account for fp representation accuracy and error accumulation; a step size of something like pi or 1/10 could spell disaster for a large range. if in doubt, use integral steps and divide ... something like <?php range(88.1,108,.2) ?> might work to recover 107.9, but would not be scalable like, say <?php array_map(create_function('$x','return $x/10;'),range(881,1079,2)) ?>.