• 27-09-2014, 21:12:34
    #1
    Merhaba arkadaşlar bana harfleri sıralayan bir yöntem lazım.

    Örneğin rakamları sıralarken;

    for($a=0; $a<25000; $a++){
    
    echo $a."<br>";
    }
    1
    2
    3
    4..
    25000
    şeklinde sıralıyor ama bana lazım olan ise harf sıralamaları.

    Yani istiyorum ki;
    a
    b
    c
    d
    e..
    
    ab
    ac
    ad..
    
    abc
    abd..
    şeklinde buna nasıl bir mantık uydurabiliriz ?
  • 27-09-2014, 21:43:21
    #2
    XYZ
    Kimlik doğrulama veya yönetimden onay bekliyor.
    http://php.net/manual/tr/function.range.php sayfasında işinize yarar bir örnek var:

    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;
    }
    
    
    $liste = createColumnsArray('zzz');
    
        foreach ($liste as $harf) {
                echo $harf.'<br>';
        }
  • 27-09-2014, 21:44:16
    #3
    Kimlik doğrulama veya yönetimden onay bekliyor.
    buyur hocam

    <?php
    
    
    
    function saynoertz($asagi, $yukari) {
        ++$yukari;
        for ($i = $asagi; $i !== $yukari; ++$i) {
            yield $i;
        }
    }
    
    foreach (saynoertz('a', 'zz') as $harf) {
        echo $harf, PHP_EOL . '<br />';
    }
    
    ?>


    Msn adlı üyeden alıntı: mesajı görüntüle
    Merhaba arkadaşlar bana harfleri sıralayan bir yöntem lazım.

    şeklinde buna nasıl bir mantık uydurabiliriz ?