0

Does anyone here knows how to shuffle string (random output string) from an array like, I have this array (refer below)

$cars = array("Volvo", "BMW", "Toyota");

function random_string(){
    //here a function to randomize or shuffle the items from the $cars array
    return $random_string;
}

echo random_string()

any help, suggestions, recommendations, clues, ideas is highly appreciated. Thank you.

1
  • 4
    array_rand() ? - echo $cars[array_rand($cars, 1)]; Commented Jul 28, 2015 at 3:25

2 Answers 2

1

You can use the php rand() method.

$random_string = $car[rand(0,count($car)-1)];
Sign up to request clarification or add additional context in comments.

Comments

1
$random_string = array("Volvo", "BMW", "Toyota");
shuffle($random_string);
print_r($random_string);

you can try this one

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.