How to get a random value from a php array?



How to get a random value from a php array?..

Answer / Siddhnath Gaur

To obtain a random value from an array in PHP, you can use the array_rand() function. Here's an example:

```php
$array = array('a', 'b', 'c');
$random_index = array_rand($array);
echo $array[$random_index];

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More PHP Interview Questions

How to define a function with any number of arguments?

1 Answers  


How to find datatype of variable in php?

1 Answers  


Is php faster than python?

1 Answers  


Write a program in php to print a table of a number?

1 Answers  


How can we register the variables into a Session?

7 Answers   HCL, Star Computers, Trikon Networks,


How is php different from other languages?

1 Answers  


Can I include php in javascript?

1 Answers  


What is php glob?

1 Answers  


Why php is also called as scripting language?

1 Answers  


How can we extract string "pcds.co.in" from a string "https://info@pcds.co.in" using regular expression of php? More on reg can you explain

0 Answers  


How to convert one date format into another in php?

1 Answers  


Tips to optimize the php script..... Suggestion for exception handling in php...

1 Answers  


Categories