array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.str-shuffle.php', 1 => 'str_shuffle', ), 'up' => array ( 0 => 'ref.strings.php', 1 => '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' => 'ja', '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 — 文字列をランダムにシャッフルする
str_shuffle() は文字列をシャッフルします。 考えられるすべての順列のうちのひとつを作成します。
この関数が生成する値は、暗号学的にセキュアではありません。そのため、これを暗号や、戻り値を推測できないことが必須の値として使っては いけません。
暗号学的にセキュアな乱数が必要な場合は、Random\Randomizer を Random\Engine\Secure と一緒に使いましょう。簡単なユースケースの場合、random_int() と random_bytes() 関数が、オペレーティングシステムの CSPRNG を使った、 便利で安全な API を提供します。
string
入力文字列。
シャッフルされた文字列を返します。
例1 str_shuffle() の例
<?php
$str = 'abcdef';
$shuffled = str_shuffle($str);
// bfdaec のような文字列を返します
echo $shuffled;
?>