<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.str-shuffle.php',
    1 => 'str_shuffle',
    2 => 'Randomly shuffles a string',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Functions',
  ),
  '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' => 'en',
    'path' => 'reference/strings/functions/str-shuffle.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.str-shuffle" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">str_shuffle</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">str_shuffle</span> &mdash; <span class="dc-title">Randomly shuffles a string</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.str-shuffle-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>str_shuffle</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="simpara">
   <span class="function"><strong>str_shuffle()</strong></span> shuffles a string.  One permutation
   of all possible is created.
  </p>
  <div class="caution"><strong class="caution">Caution</strong>
 <p class="para">
  This function does not generate cryptographically secure values, and <em>must not</em>
  be used for cryptographic purposes, or purposes that require returned values to be unguessable.
 </p>
 <p class="para">
  If cryptographically secure randomness is required, the <span class="classname"><a href="class.random-randomizer.php" class="classname">Random\Randomizer</a></span> may be
  used with the <span class="classname"><a href="class.random-engine-secure.php" class="classname">Random\Engine\Secure</a></span> engine. For simple use cases, the <span class="function"><a href="function.random-int.php" class="function">random_int()</a></span>
  and <span class="function"><a href="function.random-bytes.php" class="function">random_bytes()</a></span> functions provide a convenient and secure <abbr title="Application Programming Interface">API</abbr> that is backed by
  the operating system’s <abbr title="Cryptographically Secure PseudoRandom Number Generator">CSPRNG</abbr>.
 </p>
</div>
  <div class="caution"><strong class="caution">Caution</strong>
 <p class="simpara">
    This function uses the global Mt19937 (“Mersenne Twister”) instance as the source of randomness and thus shares its state with all other functions using the global Mt19937.
    Using any of these functions advances the sequence for <em>all</em> the other functions, regardless of scope.
  </p>
  <p class="simpara">
    Generating repeatable sequences by seeding <span class="function"><a href="function.mt-srand.php" class="function">mt_srand()</a></span> or <span class="function"><a href="function.srand.php" class="function">srand()</a></span> with a known value will also yield repeatable output from this function.
  </p>
  <p class="simpara">
    Prefer using <span class="classname"><a href="class.random-randomizer.php" class="classname">Random\Randomizer</a></span> methods in all newly written code.
 </p>
</div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.str-shuffle-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       The input string.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.str-shuffle-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the shuffled string.
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.str-shuffle-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.1.0</td>
       <td>
        The internal randomization algorithm <a href="migration71.incompatible.php#migration71.incompatible.rand-srand-aliases" class="link">has been changed</a> to use the <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html" class="link external">&raquo;&nbsp;Mersenne Twister</a> Random Number Generator instead of the libc rand function.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.str-shuffle-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>str_shuffle()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">'abcdef'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$shuffled </span><span style="color: #007700">= </span><span style="color: #0000BB">str_shuffle</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// This will echo something like: bfdaec<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$shuffled</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.str-shuffle-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="random-randomizer.shufflebytes.php" class="function" rel="rdfs-seeAlso">Random\Randomizer::shuffleBytes()</a> - Get a byte-wise permutation of a string</span></li>
    <li><span class="function"><a href="random-randomizer.shufflearray.php" class="function" rel="rdfs-seeAlso">Random\Randomizer::shuffleArray()</a> - Get a permutation of an array</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>