$imagesDir="images/tips/";
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$randomImage = $images[array_rand($images)]; // See comments
You can send a 2nd argument to array_rand()
to get more than 1.
More Related Contents:
- Removing X-Powered-By
- PHP remove commas from numeric strings
- PHP Warning: Unknown: failed to open stream
- Format output of $SimpleXML->asXML(); [duplicate]
- PHP cURL: CURLOPT_CONNECTTIMEOUT vs CURLOPT_TIMEOUT
- html5 display as image rather than “choose file” button
- Unit Testing with items that need to send headers
- $_FILE upload large file gives error 1 even though upload_max_size is bigger than the file size
- json_encode not working with a html string as value
- PHP typecasting
- Store html entities in database? Or convert when retrieved?
- How to IPC between PHP clients and a C Daemon Server?
- Doctrine2 association mapping with conditions
- Xdebug ignores breakpoints
- PDO Unbuffered queries
- Safe alternatives to PHP Globals (Good Coding Practices)
- PHP Pass Data with Redirect
- Convert Time String to Decimal Hours PHP [closed]
- Parsing HTTP_RANGE header in PHP
- Decoding numeric html entities via PHP
- phpmailer send gmail smtp timeout [duplicate]
- Allowing users to Refresh browser without the “Confirm Form Resubmission” pop-up
- Dynamically bind mysqli_stmt parameters and then bind result
- “PHP Fatal error: Class ‘HttpRequest’ not found”
- ftp_put is corrupting my movies after transfer, is it wrong?
- Installing PDO driver on MySQL Linux server
- How to Load Ajax in WordPress
- Can’t make Laravel 4 to work on localhost
- PHP: Date larger than current date
- How can you use php in a javascript function [duplicate]