array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'function.str-shuffle.php', 1 => 'str_shuffle', ), 'up' => array ( 0 => 'ref.strings.php', 1 => 'Funções de String', ), 'prev' => array ( 0 => 'function.str-rot13.php', 1 => 'str_rot13', ), 'next' => array ( 0 => 'function.str-split.php', 1 => 'str_split', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'pt_BR', 'path' => 'reference/strings/functions/str-shuffle.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
str_shuffle — Embaralha uma string aleatoriamente
str_shuffle() embaralha uma string. Uma permutação de todas as possíveis é criada.
Esta função não gera valores criptograficamente seguros e não deve ser usada para propósitos criptográficos ou fins que exijam que os valores retornados sejam impossíveis de adivinhar.
Se aleatoriedade criptograficamente segura for necessária, a classe Random\Randomizer pode ser usada com o mecanismo Random\Engine\Secure. Para casos de uso simples, as funções random_int() e random_bytes() fornecem uma API conveniente e segura que é garantida pelo CSPRNG do sistema operacional.
string
A string de entrada.
Retorna a string embaralhada.
Versão | Descrição |
---|---|
7.1.0 | O algoritmo interno de randomização mudou e agora usa o Gerador de Números Aleatórios » Mersenne Twister em vez da função rand da biblioteca libc. |
Exemplo #1 Exemplo de str_shuffle()
<?php
$str = 'abcdef';
$shuffled = str_shuffle($str);
// Isto exibirá algo como: bfdaec
echo $shuffled;
?>