Fri, 17 May 2024


How can I pick one or several random values contained in a PHP array?

By: Anton, NetArt Media
Fri, 10 July 2020

You may use the array_rand function which is available from PHP version 4.0.0.

<?php

$arr=array("netart","france","paris","media");

$arr_random=array_rand($arr,2);

echo $arr[$arr_random[0]]."<br>".$arr[$arr_random[1]];

?>


Category: PHP Examples
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox