PHP-Snippets
 php::MySQL (0)
 php::Image (4)
   » Bild - Boxskalierung
   » Hex-Farbcode -> Farb-Array
   » Farb - Aufheller
   » Farb - Abdunkler
 php::Sonstiges (4)
   » Einfache Template-Funktion
   » Simple HTTP-Post Funktion
   » Simple HTTP-Get Funktion
   » zwischen()-Funktion
 php::Spezielles (2)
   » Zeichenvorkommisse prüfen
   » Array mischen (seeded)
Snippet: Array mischen (seeded)

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
<?php

// Simple seeded random number generator
// Credits for the mechanism: 
// http://www.sitepoint.com/php-random-number-generator/
function seeded_random($seed$min$max) {
    
$seed = ($seed 125) % 2796203;
    
$res $seed % ($max $min 1) + $min;
    return Array(
$res$seed);
}

// Shuffle function
function seeded_shuffle($ar$seed) {
    
$c count($ar);
    
$tmp $ar;
    
$se $seed;
    for(
$i=0;$i<$c;$i++) {
        
$r seeded_random($se0, (count($ar) - 1));
        
$num $r[0];
        
$se $r[1];   
        
// Swap
        
$t $tmp[$i];
        
$tmp[$i] = $tmp[$num];
        
$tmp[$num] = $t;
    }   
    return 
$tmp;
}

// Example
// Call of seeded_shuffle with same array and same seed will always
// return the same shuffled array
$example_data = Array("First""Second""Third");
$shuffled seeded_shuffle($example_data12345);

print_r($shuffled);
// Array ( [0] => Second [1] => Third [2] => First )
?>