How to use shuffle in PHP

In this article, I will explain how the shuffle() function can be used in PHP.
  • 1728

shuffle() function in PHP

  • The shuffle() function is used to randomizes the order of the elements in an array.
  • The shuffle function assigns new keys to the elements in an array.
  • In shuffle() function, Any existing keys will be removed.
  • The shuffle() function returns TRUE on success.
  • The shuffle() function returns FALSE on failure.

Syntax

shuffle(array)

Parameter

  • array array is required parameter. it is the input array to use.

Example

The following example show to how the shuffle() function can be used in PHP.

<html>

<body>

<h3 style="color: goldenrod;">shuffle() function example in PHP</h3>

    <?php 

    $language_list = array(1 => "ASP.NET".'<br/>', 2 => "PHP".'<br/>', 3 =>    

    "C#".'<br/>'); 

    shuffle($language_list); 

    print_r($language_list); 

    ?>

</body>

</html>

 

Output

shufflephp.jpg
You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.