Viewed   232 times

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')



Just Try this- (tested working fine)

function createColumnsArray($end_column, $first_letters = '')
  $columns = array();
  $length = strlen($end_column);
  $letters = range('A', 'Z');

  // Iterate over 26 letters.
  foreach ($letters as $letter) {
      // Paste the $first_letters before the next.
      $column = $first_letters . $letter;

      // Add the column to the final array.
      $columns[] = $column;

      // 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;
echo "<pre>";
print_r( createColumnsArray('BZ'));

copied from

Tuesday, December 6, 2022

That would be because floating point numbers are not precise and not all numbers can be represented exactly using floats.

Monday, November 21, 2022

Use Skip then Take.

yourEnumerable.Skip(4).Take(3).Select( x=>x )

(from p in intList.Skip(x).Take(n) select p).sum()
Friday, October 14, 2022

I Created this function based on my $array element of my question.

If this is a good aproach of my question please make some comments for like pointing my mistakes. this is the output.

private function createRange($array){

    //Setting range limits.
    //Check if array has 5 digit number.
    $countDigitedNumbers = preg_grep('/d{5}/',$array);
    if(count($countDigitedNumbers) > 3){
        $rangeLimits = array(0,1000,2500,5000,10000,15000,20000,25000);
        $rangeLimits = array(0,50,250,500,1000,1500,2000,2500);
    $ranges = array();

    for($i = 0; $i < count($rangeLimits); $i++){
        if($i == count($rangeLimits)-1){
        $lowLimit = $rangeLimits[$i];
        $highLimit = $rangeLimits[$i+1];

        $ranges[$i]['ranges']['min'] = $lowLimit;
        $ranges[$i]['ranges']['max'] = $highLimit;

        foreach($array as $perPrice){
            if($perPrice >= $lowLimit && $perPrice < $highLimit){
                $ranges[$i]['values'][] = $perPrice;
    return $ranges;
Monday, September 12, 2022

If you are going to cast the timestamp values of the field to date, as suggested in another answer, performance will degrade because every single value in the column needs to be cast for comparison and simple indexes cannot be used. You would have to create a special index on the expression, like so:

CREATE INDEX some_idx ON tbl (cast(mdate AS date));

In this case the query should also be simplified to:

WHERE  mdate::date = '2011-09-12'::date; -- 2nd cast optional

However, as far as I can see, your problem is a simple typo / thinko in your query:
You switched upper & lower boundaries. Try:

WHERE  mdate >= '2011-09-12 00:00:00.0'
AND    mdate <= '2011-09-13 00:00:00.0';

Or, to simplify your syntax and be more precise:

WHERE  mdate >= '2011-09-12 00:00'
AND    mdate <  '2011-09-13 00:00';
  • There is no need to spell out seconds and fractions that are 0.
  • You don't want to include 2011-09-13 00:00, so use < instead of <=.
    Don't use BETWEEN here, for the same reason:
WHERE mdate BETWEEN '2011-09-12 00:00' AND '2011-09-13 00:00'

This would include 00:00 of the next day.

Also be aware that a column of type timestamp [without time zone] is interpreted according to your current time zone setting. The date part depends on that setting, which should generally work as expected. More details:

  • Ignoring time zones altogether in Rails and PostgreSQL
Monday, August 1, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :