PHP - shuffle only part of an array -



PHP - shuffle only part of an array -

i have array so:

$animals = array ( 'giraffe', 'lion', 'hippo', 'dog', 'cat', 'rabbit', 'fly', 'hamster', 'gerbil' 'goldfish' );

that order want array in apart these 2 - hamster , gerbil

i randomise between 1 comes first. know can use:

shuffle($animals);

to randomise them want these 2. if print_r($animals) may hamster come before gerbil time gerbil before hamster

you can splice array elements, randomize order , set them in original array:

$sub = array_splice($animals, 7, 2); shuffle($sub); array_splice($animals, 7,0, $sub); var_dump($animals);

php arrays shuffle

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -