NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - shuffle

Trieda

Koreň \ Bez triedy

Metóda - shuffle

(PHP 4, PHP 5, PHP 7)

The function shuffles an array (randomizes the order of its elements).

Beware: This function assigns new keys to the elements in the array. It'll remove any existing keys!

Note: The function uses a pseudo-random number generator, do not use is for cryptographic purposes.

Procedurálne

  • function shuffle (array &$array) : bool

Parametre

NázovDátový typPredvolená hodnotaPopis
&$arrayarray

The array to be shuffled.

Mávratovej hodnoty

Vracia: bool

Returns true on success or false on failure.

Príklady

Array shuffling:

<?php
$songs = [
    'Alan Walker - Faded',
    'Imagine Dragons - Radioactive',
    'Linkin Park - Final Masquerade',
    'Avicii - Wake Me Up',
];

shuffle($songs);
print_r($songs);

Any existing keys are removed!

<?php
$numbers = [
    'one' => 'First',
    'two' => 'Second',
    'three' => 'Third',
    'four' => 'Fourth',
    'five' => 'Fifth',
];

shuffle($numbers);
print_r($numbers);

Súvisiace manuály

      • function array_rand (array $array, int $num = 1) : mixed
      Aktivity