tami: neue Artikel anlegen, Namen finden

Beitrag lesen

hi,

es ist ja eigentlich ein shuffler, oder? der memorized, und zwar serialisiert. also eigentlich ein SerializedShuffleMemorizer.

  
<?php  
/**  
* Saves List in serialized File an picks new Item every call until End, then shuffles new.  
*/  
class MemorizedShuffle  
{  
    private $_serFileName = "";  
    private $_toShuffle = "";  
    private $_shuffled = array();  
    private $_nextItem = "";  
    /**  
     * Constructor  
     *@param string filename, array List to Shuffle  
     * @return void  
     */  
    public function __construct($serFileName, $toShuffle) {  
    $this->_serFileName = $serFileName;  
        $this->_toShuffle = $toShuffle;  
        if(!file_exists($this->_serFileName)) {  
            $this->_createNewShuffledFile();  
        }  
        $this->_read();  
    }  
    private function _createNewShuffledFile() {  
        $this->_shuffled = $this->_toShuffle;  
        shuffle($this->_shuffled);  
        $this->_write();  
    }  
    private function _write() {  
        if (false === file_put_contents($this->_serFileName, serialize($this->_shuffled))) {  
        throw new Exception ("Could not write");  
    };  
    }  
    private function _read() {  
        $this->_shuffled = unserialize(file_get_contents($this->_serFileName));  
    if (false === $this->_shuffled) {  
        throw new Exception ("Could not read");  
    }  
    }  
    public function getNext() {  
        //~ var_dump($this->_shuffled);  
        if (count($this->_shuffled) === 0) {  
            $this->_createNewShuffledFile();  
        }  
        $actualItem = array_shift($this->_shuffled);  
        $this->_write();  
        return $actualItem;  
    }  
};  
$myShuffler = new MemorizedShuffle("ColorsShuffled.ser", array("blau", "rot", "grün", "schwarz"));  
var_dump($myShuffler->getNext());  
  

mfg

tami

0 59

Array zufällig ausgeben und ausgegeben Werte merken

Sinje
  • php
  1. 0
    Siri
    • programmiertechnik
  2. 0
    Melvin Cowznofski
    1. 0
      Tom
      1. 0
        Tom
      2. 0
        Melvin Cowznofski
        1. 0
          Tom
    2. 0

      Glossar: "auskommentieren"

      Der Martin
      • programmiertechnik
      1. 0
        Matthias Apsel
    3. 0
      Matthias Apsel
      1. 0
        Melvin Cowznofski
  3. 0
    Tom
    1. 0
      Sinje
      1. 0
        Tom
  4. 0

    Ticken PHP-Programmierer anders?

    Siri
    1. 0
      Matthias Apsel
      1. 0
        Siri
        1. 0

          PHP tickt anders - wie eigentlich jede Programmiersprache

          dedlfix
          1. 0
            Siri
            1. 0
              dedlfix
    2. 0
      Tom
      1. 0
        Siri
        1. 0
          tami
          1. 0
            Tom
        2. 0
          Tom
          1. 0
            Sinje
            1. 0
              Tom
  5. 0
    Claudius L.
    1. 0
      tami
      1. 0
        Claudius L.
    2. 0
      Tom
      1. 0
        Tom
      2. 0
        Claudius L.
        1. 0
          Tom
          1. 0
            Claudius L.
            1. 0
              Tom
            2. 0
              tami
              1. 0
                tami
                1. 0

                  Wirksames File-Locking geht anders!

                  Tom
                  1. 0
                    tami
                    1. 0
                      Tom
                      1. 0
                        tami
                        1. 0

                          gehst Du eine Test-Wette mit mir ein?

                          Tom
                          • menschelei
                          1. 0
                            tami
                            1. 0

                              Und wer testet jetzt?

                              Tom
                              1. 0
                                tami
                                1. 0
                                  Tom
                                  1. 0
                                    Matthias Apsel
                                    1. 0

                                      neue Artikel anlegen, Namen finden

                                      Tom
                                      • selfhtml-wiki
                                      1. 0
                                        Matthias Apsel
                                        1. 0
                                          Tom
                                          1. 0
                                            Matthias Apsel
                                            1. 0
                                              tami
                                  2. 0

                                    Und wer testet jetzt? -> mit SQL?

                                    Gaby
                                    • datenbank
                                    1. 0
                                      Tom
              2. 0
                Tom
  6. 0

    Array zufällig ausgeben und ausgegeben Werte merken - so?

    tami
    1. 0
      Tom
  7. 1
    Tom