Random Array element in PHP

 


<?php
// Numeric/ index arrays
$cars = array('Mecedes Benz', 'Hilux', 'Highlander', 'Hummer', 'Limozien');
$randomString = null;

for ($i = 0; $i < count($cars); $i++) {
    $index = rand(0, count($cars) - 1);
    $randomString .= $cars[$index];
    print $cars[$index];
}
print $randomString;
?>

Comments

Popular posts from this blog

Create a RESTful API using PHP, My-sql and Slim-Framework

DeltaPi softwares

How to prevent form resubmission when page is refreshed (F5 / CTRL+R)