shuffle() function in PHP || PHP Shuffle Function

shuffle() function in php

Last Updated by Pooja Chikara 25-Apr-20

0 344


PHP shuffle() function is used to shuffle the keys of array elements means it change the order of array items randomly and assigns new keys. It is an inbuilt function of PHP.

Syntax:

shuffle($array);

here,

$array is a PHP array.

The return type of this function is Boolean means it can return either TRUE or FALSE. It returns 1 on success and 0 on failure.


Example:

<?php
$arr1 = array(1,2,3,4,5,6,7,8,9);
echo "<pre>";
echo "array before using shuffle function <br>";
print_r ($arr1);
shuffle($arr1);
echo "<br> Array after using shuffle function. <br>";
print_r($arr1);
?>

Output:

shuffle() function in php


Share:


Leave a Reply


Comments
    Waiting for your comments